README
Sift-Shorthand
An expansion library for Sift which supports a human readable and CLI compatible syntax.
var shorthand = require('sift-shorthand');
// Parse {a: 1} in a variety of ways
shorthand('a=1') // Key/val setting
shorthand(['a=1']) // Key/val setting within an array
shorthand('{"a":1}') // JSON
shorthand('{a:1}') // HanSON
// Parse various types of input
siftShorthand(
'a=1', // Strings are fine
['b=2', '{"c":3}'], // Array input with nested types (string + JSON)
{d: 4}, // Also objects
{'e.f': 5}, // Also dotted notation nested objects
'{g: 6}', // Also HanSON format
) //= {a: 1, b: 2, c: 3, d: 4, e: {f: 5}, g: 7}
See the testkits for more advanced examples.
Supported Syntax Types
The main API supports simple string, CSV, arrays and a variety of other input types. The below is a quick-reference table for the compatible inputs.
Name | Type | Example input | Sift Equivalent | Description |
---|---|---|---|---|
key=val |
String | foo=bar |
{foo: "bar"} |
Simple key/value assignment |
key==val |
foo==bar |
{foo: "bar"} |
Simple key/value assignment, alternative syntax | |
key!=vak |
foo!=bar |
{foo: ${ne: "bar"}} |
Negation syntax | |
key |
Boolean | foo |
{foo: true} |
Simple boolean flag |
!key |
!foo |
{foo: false} |
Simple negation boolean flag | |
key? |
foo? |
{foo: {$exists: true}} |
Checks for the existance of a key within a document | |
key!? |
foo!? |
{foo: {$exists: false}} |
Checks for the non-existance of a key within a document | |
key<number |
Number | foo<123 |
{foo: {$lt: 123}} |
Number is-less-than |
key<=number |
foo<=123 |
{foo: {$lte: 123}} |
Number is-less-or-equal-to | |
key>number |
foo>123 |
{foo: {$gt: 123}} |
Number is-greater-than | |
key>=number |
foo>=123 |
{foo: {$gte: 123}} |
Number is-greater-or-equal-to | |
key~=RE |
RegEx | foo!=o |
{foo: {$regex: 'o'}} |
Simple search-anywhere Regular Expression syntax |
key/=RE |
foo/=o |
{foo: {$regex: 'o'}} |
Simple search-anywhere Regular Expression syntax, alt syntax | |
key^=val |
foo^=bar |
{foo: {$regex: '^bar'}} |
String begins-with | |
key$=val |
foo$=val |
{foo: {$regex: 'bar
|