Add support for query languages

js-version
Anton Medvedev 4 years ago
parent 290c2a0185
commit de3d60b01d

@ -10,6 +10,7 @@
+ [Edit-in-place](#edit-in-place)
+ [Using packages](#using-packages)
* [Using .fxrc](#using-fxrc)
+ [Query language](#query-language)
* [Formatting](#formatting)
* [Other examples](#other-examples)
* [Streaming mode](#streaming-mode)
@ -130,6 +131,32 @@ curl 'https://api.github.com/repos/facebook/react/commits?per_page=100' \
> export NODE_PATH=`npm root -g`
> ```
### Query language
If you want to use query language, for example [jsonata](http://jsonata.org/) you can use helper function like this:
```js
global.jsonata = expr => require('jsonata')(expr).evaluate
```
And use it like this:
```bash
curl ... | fx 'jsonata("$sum(Order.Product.(Price * Quantity))")'
```
Instead you can create next alias in _.bashrc_ file:
```bash
alias jsonata='FX_APPLY=jsonata fx'
```
And now all code arguments to `jsonata` will be passed through `jsonata` helper. And now you can use it like this:
```bash
curl ... | jsonata '$sum(Order.Product.(Price * Quantity))'
```
## Formatting
If you need output other than JSON (for example arguments for xargs), do not return anything from the reducer.

@ -1,6 +1,10 @@
'use strict'
function reduce(json, code) {
if (process.env.FX_APPLY) {
return global[process.env.FX_APPLY](code)(json)
}
if ('.' === code) {
return json
}

Loading…
Cancel
Save