4 ms·
I wonder if someone tried to use plain JS as a filtering language? It would be more verbose but it would be easy to remember. For example: [1,2,3] | js "out
by laurent123456 4y ago
I wonder if someone tried to use plain JS as a filtering language? It would be more verbose but it would be easy to remember. For example:
[1,2,3] | js "out = 0; for (const n of this) out += n"
That would print "6". `out` would be a special variable you write to to print the result, and `this` would be the input.
- Beltalowda 4y agoA few of the tools listed here seem to work like that, or roughly similar: https://ilya-sher.org/2018/04/10/list-of-json-tools-for-command-line/ https://ilya-sher.org/2018/04/10/list-of-json-tools-for-comm... I didn't check any of them out though.
- mechanicalpulse 4y agoI've used trentm's json (formerly known as jsontool) package from npm as my default tool for command-line manipulation of JSON for many years now. It provides CLI arguments for passing JavaScript code for filtering and executing on input. I have resisted investing the time into becoming fluent in jq because I've found that many of the common use cases I have are readily handled by jsontool. https://www.npmjs.com/package/json https://www.npmjs.com/package/json Edit: added more information
- lgas 4y agoMy hope was to one day add JS eval support to https://github.com/SuperpowersCorp/refactorio https://github.com/SuperpowersCorp/refactorio but as you can tell by the timestamps I haven't found any time to work on it in the last 4 years.
- rane 4y agoNot quite that, but ramda-cli[1] which I've created solves this problem, at least for me, by offering the familiar set of functions from Ramda, and you can create pipelines with those to do operations on your data. [1]: https://github.com/raine/ramda-cli https://github.com/raine/ramda-cli
- anitil 4y agoThat's a really interesting suggestion, similar to how AWK uses $0, $1 etc.