-
-
Notifications
You must be signed in to change notification settings - Fork 12
V2: utils: take()
Eugene Lazutkin edited this page Aug 3, 2022
·
1 revision
(Since 2.2.0)
take() takes a given number of items from a stream optionally skipping some elements before that. It is returned by require('stream-chain/utils/take') 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.
-
readableObjectModeandwritableObjectModeare always set to `true. - The following custom options are recognized:
-
(optional)
nis a positive integer indicating how many items to take. Default:1. -
(optional)
skipis a non-negative integer indicating how many items to skip from the beginning before starting to take. Default:0.
-
(optional)
-
- Otherwise it is assumed to be a positive integer, same as
ndescribed above.
A constructor of the underlying stream class produced by take(). Useful to inspect objects with instanceof.
An alias to take. Useful with metaprogramming.
const {chain} = require('stream-chain');
const take = require('stream-chain/utils/take');
// get 5 items from the top
const pipeline = chain([
take(5)
// ... the rest of the pipeline
]);
// skip 10, then get 5 items
const pipeline = chain([
take({skip: 10, n: 5})
// ... the rest of the pipeline
]);