npm.io
0.2.2 • Published 9 years ago

fltrjson

Licence
Version
0.2.2
Deps
1
Vulns
0
Weekly
0
let fltr = require('fltrjson')

Installation

$ npm install fltrjson

Features

  • Filter JSON with MongoDB like Queries
  • Promised Matching
  • Streamed Matching
  • Numbers
  • Strings
  • Dates
  • Arrays
  • Objects

Examples

Simple Promised Matching
let fltr = require('fltrjson');

let query = {
	count: {
		$gt: 3,
		$lt: 9
	}
};

let json = { count: 6 };

new fltr(query).match(json)
	.then(()=> {
		console.log('Yay!');
	})
	.catch(()=> {
		console.err('Oh noes!');
	});
//=> Yay!
Simple Stream Matching
let fs   = require('fs'),
	fltr = require('fltrjson');

let query = {
	count: {
		$gt: 3,
		$lt: 9
	}
};

let logFileStream = fs.createReadStream('/var/log/myLogFile.log');

new fltr(query).on('match', (match)=> {
	if (match) {
		console.log('Yay!');
	}
}).match(logFileStream);

Keywords