-
-
Notifications
You must be signed in to change notification settings - Fork 11
V2: utils: skipWhile()
Eugene Lazutkin edited this page Aug 3, 2022
·
1 revision
(Since 2.2.0)
skipWhile()
skips items as long as a function returns a truthy value, then all items are passed. It is returned by require('stream-chain/utils/skipWhile')
and it is based on Transform.
It takes options
and returns a Transform stream.
options
can be one of these:
- an object detailed in the Node's documentation.
-
readableObjectMode
andwritableObjectMode
are always set to `true. - The following custom options are recognized:
-
(optional)
condition
is a function or an asynchronous function, which takes an item and returns a boolean. Default:() => true
.
-
(optional)
-
- Otherwise it is assumed to be a function, same as
condition
described above.
A constructor of the underlying stream class produced by skipWhile()
. Useful to inspect objects with instanceof
.
An alias to skipWhile
. Useful with metaprogramming.
const {chain} = require('stream-chain');
const skipWhile = require('stream-chain/utils/skipWhile');
// get numbers until we encounter 3
const pipeline = chain([
skipWhile(item => item !== 3)
// ... the rest of the pipeline
]);
// input: 1, 2, 3, 4, 5
// output: 3, 4, 5