miniquery v1.1.2
miniquery
miniquery allows you to query objects for a given path and returns you an
Array of values matching.
Installation
First install miniquery in you project:
npm install --save miniqueryGetting started
Then, use it:
var miniquery = require('miniquery');
var assert = require('assert');
var fruits = [{
name: 'orange'
count: 2,
colors: ['orange']
}, {
name: 'banana',
count: 0,
colors: ['yellow', 'white']
}, {
name: 'kiwi',
count: 8,
colors: ['brown', 'green']
}];
var orangeColor = miniquery('0.colors.0', [fruits]);
assert.deepEqual(orangeColor, ['orange']);
var counts = miniquery('*.count', [fruits]);
assert.deepEqual(counts, [2, 0, 8]);
var colors = miniquery('colors.#', fruits);
assert.deepEqual(colors, ['orange', 'yellow', 'white', 'brown', 'green']);Note that miniquery always returns an Array even if there is no or only one
result.
## CLI usage
Install miniquery globally:
sudo npm install -g miniqueryThen, simply run your queries on one or more JSON files. Let's assume we want to list distinct keywords on all of our NodeJS projects :
miniquery "keywords.*" ~/projects/*/package.json -p | uniq
# minimatch
# gulp
# svg
# gulp
# gulp-plugin
# (...)
# github
# REST
# HTTP
# server
# web
#servicesGet every available options by running:
miniquery -h
# Usage: miniquery [options] <query> <file ...>
#
# Options:
#
# -h, --help output usage information
# -V, --version output the version number
# -v, --verbose tell me everything!
# -j, --json output JSON
# -p, --primitive print primitives only## API
### values:Array miniquery(path:String, objs:Array)
Return the values matching the given path for the objects contained in
objs.
Contribute
Feel free to submit us your improvements. To do so, you must accept to publish your code under the MIT license.
To start contributing, first run the following to setup the development environment:
git clone git@github.com:SimpliField/miniquery.git
cd miniquery
npm installThen, run the tests:
npm test






