kld-tagged-sets

A simple utility for discovering unique and duplicate lines of text

npm install kld-tagged-sets
1 downloads in the last week
4 downloads in the last month

kld-tagged-sets

A simple utility for discovering unique and duplicate lines of text.

Example

var TaggedSet = require('kld-tagged-sets');
var set = new TaggedSet();

// add items for tag 'a'
set.add('one', 'a');
set.add('two', 'a');
set.add('three', 'a');

// add items for tag 'b'
set.add('two', 'b');
set.add('three', 'b');
set.add('four', 'b');

// show items in 'a' only
console.log("A Only");
console.log("======");
console.log(set.filter(/^a$/));
console.log();

// show items in 'b' only
console.log("B Only");
console.log("======");
console.log(set.filter(/^b$/));
console.log();

// show items in 'a' and 'b'
console.log("A and B");
console.log("======");
console.log(set.filter(/^ab$/));
console.log();

Script

This module includes a script called 'tagged-sets'. This allows you to perform set operations with the content of text files. Each file is given a specific tag. If no tag is specified, one will be generated by assigning each file an uppercase letter beginning with 'A'.

For illustrative purposes, lets say we have file1.txt with the following content:

one
two
three

And file2.txt with the following content:

two
three
four

You can perform simple set operations on the contents of those files.

tagged-sets file1.txt file2.txt A     # finds all lines in file1.txt only
tagged-sets file1.txt file2.txt B     # finds all lines in file2.txt only
tagged-sets file1.txt file2.txt AB    # finds lines in both file1.txt and file2.txt

If you wish to change the tag to something more meaningful, you can append an equal sign, '=', followed by a tag name to each file name. For example, we can find all items in file1.txt only using something like the following:

tagged-sets file1.txt=Local file2.txt=Remote Local # finds all lines in file1.txt only
npm loves you