push-stream-std

@push-stream-std/push-limit (0.0.6)

Published 2026-07-20 21:37:48 +00:00 by Dvorak

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.6
"@push-stream-std/push-limit": "0.0.6"

About this package

@push-stream-std/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-pushable';
import { collect } from '@push-stream-std/push-concat';

// 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

Why

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. If null or undefined, no items are skipped.
  • count (number | null) — Maximum number of items to emit. If null, undefined, or 0, 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 22 or later. ESM only.

Keywords

push-stream stream limit pagination
Details
npm
2026-07-20 21:37:48 +00:00
0
SEE LICENSE IN LICENSE
3.6 KiB
Assets (1)
Versions (5) View all
0.0.7 2026-07-21
0.0.6 2026-07-20
0.0.5 2026-07-20
0.0.4 2026-07-19
0.0.3 2026-07-19