README
core
Ce plugin propose une série d'instructions natives. Elles sont constamment disponibles car chargées automatiquement.
installation
npm install @ezs/core
usage
Table of Contents
- assign
- concat
- debug
- delegate
- dispatch
- dump
- env
- exchange
- extract
- group
- ignore
- keep
- pack
- parallel
- remove
- replace
- shift
- shuffle
- spawn
- swing
- time
- tracer
- transit
- truncate
- ungroup
- unpack
- validate
assign
Add a new field to an Object
.
Input file:
[{
"a": 1,
},
{
"a": 2,
},
{
"a": 3,
},
{
"a": 4,
},
{
"a": 5,
}]
Script:
[assign]
path = b.c
value = 'X'
Output:
[{
"a": 1,
"b": { "c": "X" },
},
{
"a": 2,
"b": { "c": "X" },
},
{
"a": 3,
"b": { "c": "X" },
},
{
"a": 4,
"b": { "c": "X" },
},
{
"a": 5,
"b": { "c": "X" },
}]
Parameters
Returns Object
concat
Take all String
, concat them and throw just one.
[
"a",
"b",
"c"
]
Script:
[concat]
beginWith = <
joinWith = |
endWith = >
Output:
[
"<a|b|c>"
]
Parameters
beginWith
String? Add value at the beginjoinWith
String? use value to join 2 chunkendWith
String? Add value at the end
Returns String
debug
Take Object
, print it (with its number), and throw the same object.
Parameters
level
String console level : log or error (optional, defaultlog
)text
String text before the dump (optional, defaultvalueOf
)path
String? path of field to print
Returns Object
delegate
Delegate processing to an external pipeline.
Note: works like spawn, but each chunk share the same external pipeline.
Parameters
file
String? the external pipeline is described in a filescript
String? the external pipeline is described in a string of characterscommands
String? the external pipeline is described in a objectcommand
String? the external pipeline is described in a URL-like command
Returns Object
dispatch
Dispatch processing to an external pipeline on one or more servers.
Parameters
file
String? the external pipeline is described in a filescript
String? the external pipeline is described in a string of characterscommands
String? the external pipeline is described in a objectcommand
String? the external pipeline is described in a URL-like command
Returns Object
dump
Take all Object
s and generate a JSON array
[
{ "a": 1 },
{ "a": 2 },
{ "a": 3 },
{ "a": 4 },
{ "a": 5 }
]
Script:
[dump]
indent = true
Output:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}
]
Parameters
indent
boolean indent JSON (optional, defaultfalse
)
Returns String
env
Send the input object again, while adding new environment field(s) with the
first Object
of the feed.
Parameters
Returns Object
exchange
Take Object
and throw a new item computed by the value=
parameter (which
replace the input one).
Input file:
[{
"a": "abcdefg",
"b": "1234567",
"c": "XXXXXXX"
},
{
"a": "abcdefg",
"b": "1234567",
"c": "XXXXXXX"
}]
Script:
[exchange]
value = omit('c')
Output:
[{
"a": "abcdefg",
"b": "1234567"
},
{
"a": "abcdefg",
"b": "1234567"
}]
Parameters
value
String? value to replace input object
Returns Object
extract
Take Object
and throw each value of fields
Note: extract cannot throw
undefined
ornull
values
[{
"a": "abcdefg",
"b": "1234567",
"c": "XXXXXXX"
},
{
"a": "abcdefg",
"b": "1234567",
"c": "XXXXXXX"
}]
Script:
[extract]
path = a
path = b
Output:
[
"abcdefg",
"1234567",
"abcdefg",
"1234567"
}]
Parameters
path
String? path of field to extract
Returns Object
group
Take all chunk
s, and throw them grouped by length
.
See also ungroup.
[
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h"
]
Script:
[group]
length = 3
Output:
[
[ "a", "b", "c" ],
[ "d", "e", "f" ],
[ "g", "h" ]
]
Parameters
length
Number? Size of each partition
Returns String
ignore
Takes all the chunks, and ignore the firtst N chunk
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]
Script:
[ignore]
length = 3
Output:
[{
"a": 4
},
{
"a": 5
}]
Parameters
length
Number? Length of the feed to ignore
Returns any
keep
Throw input Object
but keep only specific fields.
Input file:
[{
"a": "abcdefg",
"b": "1234567",
"c": "XXXXXXX"
},
{
"a": "abcdefg",
"b": "1234567",
"c": "XXXXXXX"
}]
Script:
[keep]
path = a
path = b
Output:
[{
"a": "abcdefg",
"b": "1234567"
},
{
"a": "abcdefg",
"b": "1234567"
}]
Parameters
path
String? path of field to keep
Returns Object
pack
Take all Object
, throw encoded String
Returns String
parallel
Takes an Object
delegate processing to X internal pipelines
Parameters
file
String? the external pipeline is described in a filescript
String? the external pipeline is described in a string of characterscommands
String? the external pipeline is described in a objectcommand
String? the external pipeline is described in a URL-like command
Returns Object
remove
Take Object
and remove it from the feed if test is true
Input file:
[{
a: "a"
},
{
a: 2
},
{
a: "b"
},
{
a: 4
},
{
a: "c"
}]
Script:
[remove]
test = get('a).isInteger()
reverse = true
Output:
[
{
a: 2
},
{
a: 4
}
]
Parameters
Returns Object
replace
Take Object
and replace it with a new object with some fields.
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]
Script:
[replace]
path = b.c
value = 'X'
Output:
[{
"b": { "c": "X" }
},
{
"b": { "c": "X" }
},
{
"b": { "c": "X" }
},
{
"b": { "c": "X" }
},
{
"b": { "c": "X" }
}]
Parameters
Returns Object
shift
Return the first Object
and close the feed
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]
Script:
[shift]
Output:
[{
"a": 1
}]
Returns Object
shuffle
Take Object
, shuffle data of the whole object or only some fields specified by path
Input file:
[{
"a": "abcdefg",
"b": "1234567"
},
{
"a": "abcdefg",
"b": "1234567"
}]
Script:
[shuffle]
path = a
Output:
[{
"a": "cadbefg",
"b": "1234567"
},
{
"a": "dcaegbf",
"b": "1234567"
}]
Parameters
path
String? path of field to shuffle
Returns Object
spawn
Delegate processing to an external pipeline, throw each chunk from the result.
Note: works like delegate, but each chunk use its own external pipeline
Parameters
file
String? the external pipeline is described in a filescript
String? the external pipeline is described in a string of characterscommands
String? the external pipeline is described in an objectcommand
String? the external pipeline is described in an URL-like commandcache
String? Use a specific ezs statement to run commands (advanced)
Returns Object
swing
Delegate processing to an external pipeline under specifics conditions
Note: works like spawn, but each chunk shares the same external pipeline.
Parameters
test
String? if test is truereverse
String reverse the test (optional, defaultfalse
)file
String? the external pipeline is described in a filescript
String? the external pipeline is described in a string of characterscommands
String? the external pipeline is described in an objectcommand
String? the external pipeline is described in an URL-like command
Returns Object
time
Measure the execution time of a script, on each chunk of input.
Parameters
script
string?
Examples
Input
[1]
Program
const script = `
[transit]
`;
from([1])
.pipe(ezs('time', { script }))
Output
[{
data: 1,
time: 15 // milliseconds
}]
Returns object
tracer
Take Object
, print a character and throw the same object.
Useful to see the progress in the stream.
Parameters
print
String character to print at each object (optional, default.
)last
String character to print at last call (optional, default.
)first
String character to print at first call (optional, default.
)
Returns Object
transit
Take Object
and throw the same object again.
Input file:
[{
"a": 1
},
{
"a": 2
}]
Script:
[transit]
Output:
[{
"a": 1
},
{
"a": 2
}]
Returns Object
truncate
Takes all the chunks, and closes the feed when the total length is equal to the parameter.
Input file:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
},
{
"a": 5
}]
Script:
[truncate]
length = 3
Output:
[{
"a": 1
},
{
"a": 2
},
{
"a": 3
}]
Parameters
length
Number? Length of the feed
Returns any
ungroup
Take all chunk
s, and throw one item for every chunk.
See also group.
[
[ "a", "b", "c" ],
[ "d", "e", "f" ],
[ "g", "h" ]
]
Script:
[ungroup]
Output:
[
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h"
]
Returns Array<any>
unpack
Take String
s or Buffer
s and throw Object
builded by JSON.parse on each line.
Returns object
validate
From an Object
, throw the same object if all rules pass
See
Input file:
[{
"a": 1,
"b": "titi"
},
{
"a": 2,
"b": "toto"
},
{
"a": false
},
]
Script:
[validate]
path = a
rule = required|number
path = a
rule = required|string
Output:
[{
"a": 1,
"b": "titi"
},
{
"a": 2,
"b": "toto"
}]
Parameters
Returns Object