File tree Expand file tree Collapse file tree 8 files changed +110
-0
lines changed
implementations/JavaScript_json-p3 Expand file tree Collapse file tree 8 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 1+ /node_modules
Original file line number Diff line number Diff line change 1+ https://github.com/jg-rp/json-p3
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 "
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments