0.0.8 • Published 4 years ago
jqts
A TypeScript implementation of jq query language for JSON
Install
npm install jqts
Usage
For TypeScript:
import jq from 'jqts';
const pattern = jq.compile('[.[].x]');
pattern.evaluate([{ x: 1, x: 2 }]); // [1, 2]
For JavaScript:
const jq = require('jqts').default;
const pattern = jq.compile('[.[].x]');
pattern.evaluate([{ x: 1, x: 2 }]); // [1, 2]
Supported Filters
| Filter | Notation | Status | 
|---|
| Identity | . | :heavy_check_mark: | 
| Object Identifier-Index | .foo .foo.bar | :heavy_check_mark: | 
| Optional Object Identifier-Index | .foo? | :heavy_check_mark: | 
| Generic Object Index | .[<string>] | :heavy_check_mark: | 
| Array Index | .[2] | :heavy_check_mark: | 
| Array/String Slice | .[10:15] | :heavy_check_mark: | 
| Array/Object Value Iterator | .[] .[]? | :heavy_check_mark: | 
| Comma | .foo, .bar | :heavy_check_mark: | 
| Pipe | .[] \| .foo | :heavy_check_mark: | 
| Parenthesis | (. + 2) * 5 | :heavy_check_mark: | 
| JSON datatypes |  | :heavy_check_mark: | 
| Array Construction | [.foo, .bar] | :heavy_check_mark: | 
| Object Construction | {foo:.bar} {baz} | :heavy_check_mark: | 
| Recursive Descent | .. |  | 
| Addition | + | :heavy_check_mark: | 
| Subtraction | - | :heavy_check_mark: | 
| Multiplication,Division,Modulo | * / % | :heavy_check_mark: | 
length | length | :heavy_check_mark: | 
utf8bytelength | utf8bytelength | :heavy_check_mark: | 
keys, keys_unsorted | keys keys_unsorted | :heavy_check_mark: | 
has(key) | has("foo") | :heavy_check_mark: | 
in | in([0, 1]) | :heavy_check_mark: | 
map | map | :heavy_check_mark: | 
map_values | map_value |  | 
path(path_expression) |  |  | 
del(path_expression) |  |  | 
getpath(PATHS) |  |  | 
setpath(PATHS; VALUE) |  |  | 
delpaths(PATHS) |  |  | 
to_entries, from_entries |  | :heavy_check_mark: | 
with_entries |  |  | 
select(boolean_expression) |  | :heavy_check_mark: | 
arrays, objects, iterables, booleans, numbers, normals, finites, strings, nulls, values, scalars |  | :heavy_check_mark: | 
empty |  | :heavy_check_mark: | 
error(message) |  | :heavy_check_mark: | 
halt |  |  | 
halt_error, halt_error(exit_code) |  |  | 
$__loc__ | 
paths, paths(node_filter), leaf_paths |  |  | 
add |  | :heavy_check_mark: | 
any |  | :heavy_check_mark: | 
any(condition), any(generator; condition) |  |  | 
all |  | :heavy_check_mark: | 
all(condition), all(generator; condition) |  |  | 
flatten, flatten(depth) |  | :heavy_check_mark: | 
range(upto), range(from;upto), range(from;upto;by) |  | :heavy_check_mark: | 
floor |  | :heavy_check_mark: | 
sqrt |  | :heavy_check_mark: | 
tonumber |  | :heavy_check_mark: | 
tostring |  | :heavy_check_mark: | 
type |  | :heavy_check_mark: | 
infinite, nan, isinfinite, isnan, isfinite, isnormal |  | :heavy_check_mark: | 
sort, sort_by(path_expression) |  | :heavy_check_mark: | 
group_by(path_expression) |  | :heavy_check_mark: | 
min, max, min_by(path_exp), max_by(path_exp) |  | :heavy_check_mark: | 
unique, unique_by(path_exp) |  | :heavy_check_mark: | 
reverse |  | :heavy_check_mark: | 
contains(element) |  | :heavy_check_mark: | 
indices(s) |  | :heavy_check_mark: | 
index(s), rindex(s) |  | :heavy_check_mark: | 
inside |  | :heavy_check_mark: | 
startswith(str) |  | :heavy_check_mark: | 
endswith(str) |  | :heavy_check_mark: | 
combinations, combinations(n) |  | :heavy_check_mark: | 
ltrimstr(str) |  |  | 
rtrimstr(str) |  |  | 
explode |  |  | 
implode |  |  | 
split(str) |  |  | 
join(str) |  |  | 
ascii_downcase, ascii_upcase |  |  | 
while(cond; update) |  |  | 
until(cond; next) |  |  | 
recurse(f), recurse, recurse(f; condition), recurse_down |  |  | 
walk(f) |  |  | 
$ENV, env |  |  | 
transpose |  |  | 
bsearch(x) |  |  | 
String interpolation - \(foo) |  |  | 
| Convert to/from JSON |  |  | 
| Format strings and escaping |  |  | 
| Dates |  |  | 
| SQL-Style Operators |  |  | 
| builtins |  |  | 
==, != |  |  | 
| if-then-else |  |  | 
>, >=, <=, < |  |  | 
| and/or/not | and, or, not |  | 
| Alternative operator | // | :heavy_check_mark: | 
| try-catch |  |  | 
| Breaking out of control structures |  |  | 
| Error Suppression / Optional Operator | ? |  | 
| Regular expressions (PCRE) |  |  | 
| Variable / Symbolic Binding Operator |  |  | 
| Destructuring Alternative Operator |  |  | 
| Defining Functions |  |  | 
| Scoping |  |  | 
| Reduce |  |  | 
| Recursion |  |  | 
| Generators and Iterators |  |  | 
| Math |  |  | 
| I/O |  |  | 
| Streaming |  |  | 
| Assignment |  |  | 
| Modules |  |  | 
| Colors |  |  | 
License
MIT