Registry / auth-security / iso-random-stream

iso-random-stream

JSON →
library2.0.2jsnpmunverified

iso-random-stream provides an isomorphic (Node.js and browser compatible) readable stream for cryptographic random bytes. In Node.js environments, it leverages `crypto.randomBytes`, while in browsers, it utilizes `Crypto.getRandomValues()` for secure randomness. The package is currently at version 2.0.2, primarily releasing bug fixes and minor updates after a significant breaking change in version 2.0.0. The v2.0.0 release refactored the internal implementation, removed an explicit `Buffer` dependency, and introduced first-party TypeScript type definitions. Unlike some alternatives, it offers a streaming interface, which is beneficial for generating large quantities of random data without consuming excessive memory upfront.

npm install iso-random-stream
INSTALL
IMPORT
SIG · ISO-RANDOM-STREAM
I
iso-random-stream
auth-securityjavascriptv2.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

randomStream
import { randomStream } from 'iso-random-stream';
import randomStream from 'iso-random-stream';
Since v2.0.0, `randomStream` is a named export. Despite conflicting v2.0.0 release notes, it is not a default export.
randomStream (CommonJS)
const { randomStream } = require('iso-random-stream');
const randomStream = require('iso-random-stream');
The `randomStream` function is a named export, requiring destructuring for CommonJS.

Demonstrates how to create a readable stream of 100 random bytes and pipe it to a writable stream for consumption.

import { randomStream } from 'iso-random-stream'; import { Writable } from 'stream'; // Create a stream that produces 100 random bytes const stream = randomStream(100); // Create a writable stream to consume the bytes and print them as hex const consumer = new Writable({ write(chunk, encoding, callback) { console.log(`Received chunk (${chunk.length} bytes):`, chunk.toString('hex')); callback(); } }); // Pipe the random bytes stream to the consumer stream.pipe(consumer); // Listen for the 'finish' event when all bytes have been generated and consumed consumer.on('finish', () => { console.log('Finished generating and consuming 100 random bytes.'); });
Debug
Known issues
breakingVersion 2.0.0 introduced significant breaking changes. Internally, the direct dependency on the `buffer` module was removed. This affects how random data is processed and potentially how consumers handle the stream's output if they relied on specific `Buffer` characteristics from prior versions. Output is now typically `Uint8Array` via Node.js streams.
fix
Review how you handle stream chunks, especially if you had explicit `Buffer` checks or transformations. Update bundler configurations to remove any `buffer` polyfills that were previously required for this library.
affects: >=2.0.0
gotchaThe v2.0.0 release notes incorrectly state "named exports removed." Despite this, `iso-random-stream` *continues* to use named exports (e.g., `randomStream`), as reflected in its current source code and documentation. Developers should continue to import `randomStream` as a named export.
fix
Always use named imports: `import { randomStream } from 'iso-random-stream'` (ESM) or `const { randomStream } = require('iso-random-stream')` (CommonJS).
affects: >=2.0.0
gotchaVersion 2.0.0 introduced official TypeScript type definitions directly within the package. If you were previously using `@types/iso-random-stream` with v1.x, this external types package is no longer necessary and should be removed to avoid type conflicts.
fix
Remove `@types/iso-random-stream` from your `devDependencies` in `package.json`.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'randomStream')
Attempting to access `require('iso-random-stream').randomStream` without destructuring when the root export is not an object with a `randomStream` property, or if using a default import incorrectly.
fix
Ensure you are destructuring the named export: `const { randomStream } = require('iso-random-stream');` for CommonJS or `import { randomStream } from 'iso-random-stream';` for ESM.
TypeError: iso_random_stream_1.randomStream is not a function
Incorrectly importing `randomStream` as a default export in an environment where it expects a named export, common in TypeScript or transpiled JavaScript.
fix
Ensure `randomStream` is imported as a named export: `import { randomStream } from 'iso-random-stream';`.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
iso-random-stream — npm install iso-random-stream · libregistry