node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



A tag composer module for Node.js

This module lets you build a set of tags by combining and expanding existing lists of tags. Tags are character strings that don't contain any punctuation or spaces. The tags are parsed out of a comma or space separated line of text, and duplicates are removed.

For example:

"foo, bar, zoo" -> ['foo','bar','zoo']
"foo bar zoo" -> ['foo','bar','zoo']


If you're using this module, feel free to contact me on twitter if you have any questions! :) @rjrodger

This module works on both Node.js and browsers.

Current Version: 0.1.2

Tested on: Node.js 0.10.29, Chrome 29, Firefox 23, Safari 5.1, Opera 12.11

Build Status

Quick examples

To parse a string containing tags:

var tagx = require('tagx')
var tags = tagx("foo bar zoo")
// prints [ 'foo', 'bar', 'zoo' ]

You can combine multiple tag strings:

var tagx = require('tagx')
tags = tagx("a b c","d e f")
// prints [ 'a', 'b', 'c', 'd', 'e', 'f' ]

You can make tags case-insensitive:

var uncase = tagx({case:false})
tags = uncase("a A bb bB BB")
// prints [ 'a', 'bb' ]

You can define fixed tags that get added to any parsed tags:

var abc = tagx({},'a b c')
tags = abc("x y z")
// prints [ 'a', 'b', 'c', 'x', 'y', 'z' ]

You can define negative tags (prefix with !) that cancel out positive tags:

tags = tagx("a  b !b  !c c")
// prints [ 'a' ]

You can also define tag expansions, where certain tags expand to become a set of tags (negatives still work, and infinite cycles are detected):

var expand = tagx({expand:{ foo:'a b c !d', u:'v', v:'u' }})
tags = expand("foo !c d e f u")
// prints [ 'a', 'b', 'e', 'f', 'u' ]
// foo -> a,b as !c and d cancel c !d
// u -> v -> u and stops


You'll need:

sudo npm install phantomjs uglify-js -g

Test with:

npm test