mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-11-11 03:01:51 -05:00
fix(jsontools): read Node.js input from stdin (#14190)
This commit is contained in:
@@ -22,14 +22,17 @@ fi
|
||||
# Define json tools for each method
|
||||
case "$JSONTOOLS_METHOD" in
|
||||
node)
|
||||
# node doesn't make it easy to deal with stdin, so we pass it as an argument with xargs -0
|
||||
# Read stdin directly so input is not limited by command-line argument size.
|
||||
function pp_json() {
|
||||
xargs -0 node -e 'console.log(JSON.stringify(JSON.parse(process.argv[1]), null, 4));'
|
||||
node -e '
|
||||
const input = require("fs").readFileSync(0, "utf8");
|
||||
console.log(JSON.stringify(JSON.parse(input), null, 4));
|
||||
'
|
||||
}
|
||||
function is_json() {
|
||||
xargs -0 node -e '
|
||||
node -e '
|
||||
try {
|
||||
json = JSON.parse(process.argv[1]);
|
||||
JSON.parse(require("fs").readFileSync(0, "utf8"));
|
||||
console.log("true");
|
||||
process.exit(0);
|
||||
} catch (e) {
|
||||
@@ -39,10 +42,14 @@ case "$JSONTOOLS_METHOD" in
|
||||
'
|
||||
}
|
||||
function urlencode_json() {
|
||||
xargs -0 node -e "console.log(encodeURIComponent(process.argv[1]))"
|
||||
node -e '
|
||||
console.log(encodeURIComponent(require("fs").readFileSync(0, "utf8")));
|
||||
'
|
||||
}
|
||||
function urldecode_json() {
|
||||
xargs -0 node -e "console.log(decodeURIComponent(process.argv[1]))"
|
||||
node -e '
|
||||
console.log(decodeURIComponent(require("fs").readFileSync(0, "utf8")));
|
||||
'
|
||||
}
|
||||
;;
|
||||
python3)
|
||||
|
||||
Reference in New Issue
Block a user