@push-stream-std/push-sort (0.0.5)
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.5"@push-stream-std/push-sort": "0.0.5"About this package
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-values';
import { collect } from '@push-stream-std/push-collect';
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
Description
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])
comparator—function(a, b)— Standard sort comparison function. Should return a negative number ifa < b, positive ifa > b, zero if equal.options.maxSize(number, defaultInfinity) — Maximum number of items to buffer. When exceeded, the stream ends withnew 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 18 or later. ESM only.
License
MIT