@push-stream-std/push-limit (0.0.3)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-limit@0.0.3"@push-stream-std/push-limit": "0.0.3"About this package
push-limit
Skip offset items, then take limit items (pagination).
Published as @push-stream-std/push-limit.
Synopsis
import { limit } from '@push-stream-std/push-limit';
import { values } from '@push-stream-std/push-values';
import { collect } from '@push-stream-std/push-collect';
// Skip 2 items, then take 3
values([10, 20, 30, 40, 50, 60, 70])
.pipe(limit(2, 3))
.pipe(collect((err, results) => {
console.log(results); // [30, 40, 50]
}));
Install
npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-limit
Description
A push-stream through operator that skips offset items, then emits at most count items downstream. After the limit is reached the stream ends automatically. Supports pagination patterns (pass different offsets per page), "take first N" (offset 0), and unbounded skip (count omitted). An optional onLimit callback fires when the limit is hit.
API
limit(offset, count, onLimit)
Creates a through stream that skips items then takes at most count items.
Parameters:
offset(number | null) — Number of items to skip before emitting. Ifnullorundefined, no items are skipped.count(number | null) — Maximum number of items to emit. Ifnull,undefined, or0, emits all remaining items (or none if 0 with skip). If negative, the stream ends immediately.onLimit(function, optional) — Called once when the emission limit is reached.
Returns: A push-stream through.
Tests
npm test
Tests cover offset-only, count-only, combined offset+count, null/undefined parameters (pass-through), onLimit callback, and proper stream termination when the limit is reached.
Requirements
Node.js 18 or later. ESM only.
License
MIT