
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@jq-tools/jq
Advanced tools
This library intends to implement a fully functional jq interpreter that could be used in the browser or in Node.js.
For more info about the jq language see its official homepage.
yarn add -E @jq-tools/jq
From code, you can either use the jq
template tag or the evaluate
method. It is also possible to use the interpreter
from the command line.
The interpreter should currently support many of jq's features. However, not everything is supported yet. The following features still lack an implementation:
@base64
and @base64d
)add/0
, all/0
, all/1
, all/2
, any/0
, any/1
, any/2
, del/1
, delpaths/1
, empty/0
, endswith/1
, first/0
, first/1
, from_entries/0
, group_by/1
, has/1
, index/1
, indices/1
, isempty/1
, join/1
, keys/0
, last/0
, last/1
, length/0
, limit/2
, map/1
, match/1
, match/2
, not/0
, nth/1
, nth/2
, range/1
, range/2
, range/3
, rindex/1
, round/0
, select/1
, sort/0
, sort_by/1
, split/1
, startswith/1
, sub/2
, sub/3
, test/1
, test/2
, to_entries/0
, tostring/0
, type/0
, unique/0
, unique_by/1
, with_entries/1
jq
template tag (jq<In=any, Out=unknown>
)Parses the jq code from the template string and returns a function of shape
(input: In[] | IterableIterator<In>) => IterableIterator<Out>
. This function can be used to apply the defined jq
filter to some input data.
import { jq } from '@jq-tools/jq';
const transform = jq<number, number>`.[] | . * 2`;
Array.from(transform([1, 2, 3]));
[2, 4, 6]
evaluate(ast: ProgAst, input: any[] | IterableIterator<any>): IterableIterator<any>
Evaluates the given jq AST against the provided input.
import { evaluate, parse } from '@jq-tools/jq';
Array.from(evaluate(parse(`.[] | . * 2`), [1, 2, 3]));
[2, 4, 6]
You can use the jq interpreter from the command line:
echo '5' | yarn jq '.+5' # Outputs: 10
format(code: string): string
Formats the provided jq code
import { format } from '@jq-tools/jq';
format(`[.[] | {
"firstName" : .firstName ,
lastName: .surname
}]
`);
[.[] | {
"firstName": .firstName,
lastName: .surname,
}]
print(ast: ProgAst): string
Generates code from the provided jq AST.
import { print } from '@jq-tools/jq';
print({
expr: { expr: { type: 'identity' }, type: 'iterator' },
type: 'root',
});
.[]
The parser should be able to handle any jq syntax except for the modules.
For more information about the AST refer to its TypeScript types.
parse(code: string): ProgAst
Parses the provided jq code and returns its AST.
import { parse } from '@jq-tools/jq';
parse('.[].a | {"a": 5 + ., "--\\(. * 2)--": . + 4}');
{
"expr": {
"left": {
"expr": {
"expr": {
"type": "identity"
},
"type": "iterator"
},
"index": "a",
"type": "index"
},
"operator": "|",
"right": {
"entries": [
{
"key": {
"interpolated": false,
"type": "str",
"value": "a"
},
"value": {
"left": {
"type": "num",
"value": 5
},
"operator": "+",
"right": {
"type": "identity"
},
"type": "binary"
}
},
{
"key": {
"interpolated": true,
"parts": [
"--",
{
"left": {
"type": "identity"
},
"operator": "*",
"right": {
"type": "num",
"value": 2
},
"type": "binary"
},
"--"
],
"type": "str"
},
"value": {
"left": {
"type": "identity"
},
"operator": "+",
"right": {
"type": "num",
"value": 4
},
"type": "binary"
}
}
],
"type": "object"
},
"type": "binary"
},
"type": "root"
}
FAQs
jq for js
The npm package @jq-tools/jq receives a total of 1,017 weekly downloads. As such, @jq-tools/jq popularity was classified as popular.
We found that @jq-tools/jq demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.