-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Brett Zamir <brettz9@yahoo.com>
- Loading branch information
Showing
5 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env node | ||
import {readFile} from 'fs/promises'; | ||
import {JSONPath as jsonpath} from '../dist/index-node-esm.js'; | ||
|
||
const file = process.argv[2]; | ||
const path = process.argv[3]; | ||
|
||
try { | ||
const json = JSON.parse(await readFile(file, 'utf8')); | ||
runQuery(json, path); | ||
} catch (e) { | ||
/* eslint-disable no-console -- CLI */ | ||
console.error(`usage: ${process.argv[1]} <file> <path>\n`); | ||
console.error(e); | ||
/* eslint-enable no-console -- CLI */ | ||
process.exit(1); | ||
} | ||
|
||
/** | ||
* @typedef {any} JSON | ||
*/ | ||
|
||
/** | ||
* @param {JSON} json | ||
* @param {string} pth | ||
* @returns {void} | ||
*/ | ||
function runQuery (json, pth) { | ||
const result = jsonpath({ | ||
json, | ||
path: pth | ||
}); | ||
|
||
// eslint-disable-next-line no-console -- CLI | ||
console.log(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters