Update doc.md

master
Anton Medvedev 2 years ago
parent 534e0db987
commit 76e67edc41

@ -1,7 +1,8 @@
# Documentation # Documentation
`fx` can work in two modes: as reducer or interactive. The **fx** can work in two modes: as a reducer or an interactive viewer.
To start interactive mode pipe any JSON into `fx`:
To start the interactive mode pipe a JSON into **fx**:
```sh ```sh
$ curl ... | fx $ curl ... | fx
@ -15,19 +16,19 @@ $ fx data.json
## Reducers ## Reducers
If any additional arguments was passed, fx converts it to a function which takes If any additional arguments was passed, **fx** converts it to a function which
JSON as argument named `x`. takes the JSON as an argument named `x`.
By default, fx uses builtin JavaScript VM ([goja](https://github.com/dop251/goja)), By default, **fx** uses builtin JavaScript VM ([goja](https://github.com/dop251/goja)),
but fx also can be used with [node](#node), [python](#python), or [ruby](#ruby). but **fx** also can be used with [node](#node), [python](#python), or [ruby](#ruby).
### JavaScript ### JavaScript
```sh ```sh
FX_LANG=js export FX_LANG=js
``` ```
An example of anonymous function used as reducer: An example of anonymous function used as a reducer:
```sh ```sh
$ echo '{"foo": [{"bar": "value"}]}' | fx 'x => x.foo[0].bar' $ echo '{"foo": [{"bar": "value"}]}' | fx 'x => x.foo[0].bar'
value value
@ -57,6 +58,8 @@ $ echo '{"name": "fx", "count": 0}' | fx '{...this, count: 1}'
} }
``` ```
Get the list
### Dot ### Dot
Fx supports simple JS-like syntax for accessing data, which can be used with any Fx supports simple JS-like syntax for accessing data, which can be used with any
@ -86,10 +89,10 @@ ANTON
### Node ### Node
```sh ```sh
FX_LANG=node export FX_LANG=node
``` ```
### Npm packages ### NPM Packages
Use any npm package by installing it globally. Create _.fxrc.js_ file in `$HOME` Use any npm package by installing it globally. Create _.fxrc.js_ file in `$HOME`
directory, and require any packages or define global functions. directory, and require any packages or define global functions.
@ -135,11 +138,11 @@ const _ = require('lodash')
### Python ### Python
```sh ```sh
FX_LANG=python export FX_LANG=python
``` ```
Or Or
```sh ```sh
FX_LANG=python3 export FX_LANG=python3
``` ```
Example: Example:
@ -151,7 +154,7 @@ fx data.json '[x["age"] + i for i in range(10)]'
### Ruby ### Ruby
```sh ```sh
FX_LANG=ruby export FX_LANG=ruby
``` ```
Example: Example:
@ -162,7 +165,7 @@ fx data.json 'x.to_a.map {|x| x[1]}'
## Streaming mode ## Streaming mode
`fx` supports line-delimited JSON streaming and concatenated JSON streaming. The **fx** supports line-delimited JSON streaming and concatenated JSON streaming.
```sh ```sh
$ kubectl logs ... | fx .message $ kubectl logs ... | fx .message

Loading…
Cancel
Save