npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tags-system

v1.1.7

Published

A reusable tags system.

Downloads

5

Readme

tags-system

Build Status codecov

tags-system is an Hapi plugin which allow you to use tags on your application. When registered to a Hapi server the plugin will automatically create the tables tag, categories and tags_categories in Postgres:

Tags

| field | data-type | | --------------------- | | id | integer | | name | varchar(50) | | active | boolean |

categories

| field | data-type | | --------------------- | | id | integer | | name | varchar(50) | | active | boolean |

tags_categories

| field | data-type | | ------------------------ | | tags_id | integer | | categories_id | integer |

The tags-system plugin take also an option where the content of these tables can be passed. This allow to initialise quickly the tables:

plugin options:

{
  tags: require('./data/tags.json') // the json file which Initialise the tags database
  categories: require(./data/categories.json) // the json file which Initialise the categories
  pool: the_postgres_pool
}

Functions

addTags(tableName, itemId, tagIds, cb)

tableName = 'organisations' or 'challenges' itemId represents the id of the org or challenge you want to add tags to tagIds = an array of all tag ids you now want related to the given org/challenge

getAllActive(cb)

returns a parent array of active categories containing child arrays of active child tags. Each member of the parent array is of the form:

{ category_id: 9,
  category_name: 'BIOLOGICAL CYCLE',
  tags:
  [ { tag_id: 87, tag_name: 'Agriculture',              selected: false },
    { tag_id: 89, tag_name: 'Anaerobic digestion',      selected: false },
    { tag_id: 91, tag_name: 'Biochemical extraction',   selected: false  }
]
}

The categories array and the inner tags array are ordered alphabetically. If no categories or tags are found, it will return an empty array. "selected" will always be false when using getAllActive

getTagsForEdit(tableName, id, cb)

Similar to getAllActive function. At the moment, tableName can be 'challenges', in the future we will be able to call it with 'organisations' returns an array of active categories and active child tags with objects of the form:

[
  { category_id: 9,
    category_name: 'BIOLOGICAL CYCLE',
    selected: true, // `selected: true` will only be present when category has a selected child tag
    tags:
    [ { tag_id: 87, tag_name: 'Agriculture',              selected: false },
      { tag_id: 89, tag_name: 'Anaerobic digestion',      selected: false },
      { tag_id: 91, tag_name: 'Biochemical extraction',   selected: true  }
    ]
  },
  { category_id: 1,
    category_name: 'MATH',
    // note there is no `selected: true`
    tags:
    [ { tag_id: 89, tag_name: 'Algebra',  selected: false } ]
  }
]

The categories array and the inner tags array are ordered alphabetically. If no categories or tags are found, it will return an empty array.

how

  • Install the package npm install tags-system --save
  • Create a json file on your app which represent the tags
  • register the plugin in your app:
server.register([
    { register: require('tags-postgres'), options: options }
], function () {
    server.route(routes);
    server.start();
});

For a complete example you can have a look at the example folder of this plugin.

Why??

  • independent system, just require this plugin instead of creating a new tags system in your app
  • works with your existing project and database. Adding a tag will create the right table and element in Postres without intefering with your existing database

Questions?

Have a look at the issues