Skip to content

Commit dfcd638

Browse files
jg-rpcburgmer
authored andcommitted
Add json-p3
1 parent 8e0177b commit dfcd638

File tree

8 files changed

+110
-0
lines changed

8 files changed

+110
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/jg-rp/json-p3
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = implementations/JavaScript_json-p3
2+
builddir = $root/build
3+
4+
rule install
5+
command = (cd $root && npm install) && echo > $out
6+
7+
build $builddir/node_modules_installed: install | $root/package.json $root/package-lock.json
8+
9+
build $root/install: phony $builddir/node_modules_installed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
3+
const {jsonpath} = require('json-p3');
4+
5+
const selector = process.argv[2];
6+
7+
const stdin = process.stdin,
8+
stdout = process.stdout,
9+
inputChunks = [];
10+
11+
stdin.resume();
12+
stdin.setEncoding('utf8');
13+
14+
stdin.on('data', function (chunk) {
15+
inputChunks.push(chunk);
16+
});
17+
18+
stdin.on('end', function () {
19+
const input = inputChunks.join(),
20+
json = JSON.parse(input);
21+
22+
try {
23+
const result = jsonpath.query(selector, json).values();
24+
if (result === undefined) {
25+
console.error(result);
26+
process.exit(1);
27+
}
28+
stdout.write(JSON.stringify(result));
29+
} catch (e) {
30+
console.error(e.message);
31+
process.exit(1);
32+
}
33+
});

implementations/JavaScript_json-p3/package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "javascript_json-p3",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"json-p3": "^1.0.0"
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
readonly script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
cd "$script_dir"
7+
8+
readonly tmp_stdout="/tmp/node_json-p3.stdout.$$"
9+
readonly tmp_stderr="/tmp/node_json-p3.stderr.$$"
10+
11+
output_and_cleanup() {
12+
local filter_syntax_error_in_vm="evalmachine.<anonymous>:1"
13+
if ! grep "$filter_syntax_error_in_vm" < "$tmp_stdout"; then
14+
cat "$tmp_stdout"
15+
>&2 cat "$tmp_stderr"
16+
fi
17+
rm "$tmp_stdout"
18+
rm "$tmp_stderr"
19+
}
20+
21+
trap output_and_cleanup EXIT
22+
23+
./index.js "$@" > "$tmp_stdout" 2> "$tmp_stderr"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
readonly script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
cd "$script_dir"
7+
8+
npm i json-p3@latest

0 commit comments

Comments
 (0)