Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including miniquery with all npm packages installed. Try it out:

var miniquery = require("miniquery")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

miniquery v1.1.2

Simplest object querying tool

miniquery

miniquery allows you to query objects for a given path and returns you an Array of values matching.

NPM version Build status Dependency Status devDependency Status Coverage Status Code Climate

Installation

First install miniquery in you project:

npm install --save miniquery

Getting 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 miniquery

Then, 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
#services

Get 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 install

Then, run the tests:

npm test

Stats

NPM NPM

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free