对命令行(node.js)中的数据使用自定义(“动态”)javascript函数
有没有一种方法可以使用javascript函数“通过管道传输数据” 差不多对命令行(node.js)中的数据使用自定义(“动态”)javascript函数,javascript,node.js,command-line,command-line-interface,Javascript,Node.js,Command Line,Command Line Interface,有没有一种方法可以使用javascript函数“通过管道传输数据” 差不多 $ curl -s https://api.github.com/users/egamma/gists | node.exe --magic "JSON.parse(arguments[0]).map(x=>x.files[0].filename + ' -- ' + x.description)" | sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/" test.js .esl
$ curl -s https://api.github.com/users/egamma/gists
| node.exe --magic "JSON.parse(arguments[0]).map(x=>x.files[0].filename + ' -- ' + x.description)"
| sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/"
test.js
.eslintrc.json Visual Studio Code default .eslintrc.json
甚至
$ curl -s https://api.github.com/users/egamma/gists
| node.exe --magic "x=>JSON.parse(x).map(y=>y.files[0].filename + ' -- ' + y.description)"
| sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/"
test.js
.eslintrc.json Visual Studio Code default .eslintrc.json
或
Node.js有-e
和-p
,它们只能作为参数使用,所以我不知道如何将数据(参数)和代码分开。此外,使用参数会限制数据长度
不写临时文件的难看的解决方法是
$ node.exe -p "JSON.parse($(curl -s https://api.github.com/users/egamma/gists)).map(x=>x.files[0].filename + ' -- ' + x.description)"
| sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/"
test.js
.eslintrc.json Visual Studio Code default .eslintrc.json
(注意,我在Windows上使用Git Bash,因此,
node.exe
是一种解决方法)或者您可以放弃尝试使用node,直接使用。或者您可以放弃尝试使用node,直接使用。
$ node.exe -p "JSON.parse($(curl -s https://api.github.com/users/egamma/gists)).map(x=>x.files[0].filename + ' -- ' + x.description)"
| sed -E "s/^.*'(.*) -- (.*)'.*$/\1\t\2/"
test.js
.eslintrc.json Visual Studio Code default .eslintrc.json