push-stream-std

@push-stream-std/push-sort (0.0.7)

Published 2026-07-21 04:00:38 +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-sort@0.0.7
"@push-stream-std/push-sort": "0.0.7"

About this package

@push-stream-std/push-sort

Buffer an entire push-stream, then emit values in sorted order.

Published as @push-stream-std/push-sort.

Synopsis

import { sort } from '@push-stream-std/push-sort';
import { values } from '@push-stream-std/push-pushable';
import { collect } from '@push-stream-std/push-concat';

values([3, 1, 4, 1, 5, 9])
  .pipe(sort((a, b) => a - b))
  .pipe(collect((err, results) => {
    console.log(results); // [1, 1, 3, 4, 5, 9]
  }));

With max buffer size limit:

values([3, 1, 4, 1, 5, 9])
  .pipe(sort((a, b) => a - b, { maxSize: 1000 }))
  .pipe(collect((err, results) => {
    if (err) console.error('buffer exceeded:', err.message);
    else console.log(results);
  }));

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

Why

A push-stream through operator that accumulates all incoming values into an internal buffer. When the source ends successfully, the buffer is sorted using the provided comparator and each value is emitted in sorted order to the sink. An optional maxSize limit prevents unbounded memory growth — exceeding the limit causes the stream to end with an error with code MAX_SIZE_EXCEEDED. Values arriving after the stream has ended are ignored.

API

sort(comparator, [options])

  • comparatorfunction(a, b) — Standard sort comparison function. Should return a negative number if a < b, positive if a > b, zero if equal.
  • options.maxSize (number, default Infinity) — Maximum number of items to buffer. When exceeded, the stream ends with new Error('Max size exceeded') with .code === 'MAX_SIZE_EXCEEDED'.

Returns a push-stream through. All writes buffer data; sorting and emission happen when end() is called without an error.

Tests

npm test

Tests cover numeric sorting, reverse sorting, maxSize limit enforcement, error propagation on abort, and empty stream handling.

Requirements

Node.js 22 or later. ESM only.

Keywords

push-stream stream sort buffer order
Details
npm
2026-07-21 04:00:38 +00:00
0
SEE LICENSE IN LICENSE
latest
3.5 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