How fx processes data using JavaScript functions
masterfx treats command-line arguments as JavaScript functions. It implements a pipeline pattern where the input data is passed to the first function, and the result of that function is passed as the input to the next function in the chain.
Accessing Input Data
- Arrow Functions: Use an explicit argument like
x => x.field. - Implicit Input (
.): Start an expression with a.to access properties of the input data without writingx => x. thiskeyword: Usethisto refer to the current input data.
Examples
Pipeline with arrow functions:
echo '{"name": "world"}' | fx 'x => x.name' 'x => `Hello, ${x}!`'Pipeline with implicit dot and this:
echo '{"name": "world"}' | fx '.name' '`Hello, ${this}!`'Using standard JS functions:
echo '{"name": "world"}' | fx 'Object.keys'echo '{"name": "world"}' | fx 'x => x.name' 'x => `Hello, ${x}!`'