Hey Meteor Community!
I’m excited to share @bluehive/random, a TypeScript-first, fully unit-tested, 100% API-compatible port of Meteor’s random
package, now available as a modern npm package!
GitHub Repo | Live Demos & Docs
Why Another Random Port?
There are a few Meteor random ports, but I needed a solution that checks these boxes:
- Full TypeScript support (with complete type definitions)
- Comprehensive unit tests (89%+ coverage, 79 tests, see coverage reports)
- GitHub Actions CI/CD for every commit/PR
- Modern ESM/CommonJS packaging (works in Node, browsers, bundlers)
- Zero runtime dependencies
- API and deterministic output match Meteor’s original package
- Easy migration: existing Meteor code should “just work” after changing the import.
- Live interactive docs and playground
I’m migrating Meteor methods to a Fastify API for docs.bluehive.com and needed a drop-in replacement for Random.id()
and Random.secret()
that would behave identically—especially for session tokens and reproducible test data.
Features
- Cryptographically secure: Uses
crypto.randomBytes()
(Node) orwindow.crypto.getRandomValues()
(browser); falls back to Alea PRNG with entropy if crypto is unavailable. - API Compatibility: All Meteor Random methods supported:
import { Random } from '@bluehive/random'; const id = Random.id(); const secret = Random.secret(); const seeded = Random.createWithSeeds(42);
- Deterministic output: Seeded generators produce the same sequence as Meteor’s implementation.
- Character sets:
- IDs: “Unmistakable” (avoids 0, 1, I, l, O)
- Secrets: URL-safe base64
- Hex strings: lowercase hex
- Zero dependencies and modern JS packaging
- Full coverage and test suite (89%+ coverage, 79 tests)
- Works everywhere (Node, browsers, ESM/CJS, React/Next, etc.)
- Live playground: Try it here
TypeScript & Testing
- Every API is fully typed; includes advanced usage and generic utilities (see the TypeScript examples)
- 79 unit tests, including edge cases and environment fallbacks
- Test commands:
npm test npm run test:coverage
Migration from Meteor
npm install @bluehive/random
- Change imports:
- import { Random } from 'meteor/random'; + import { Random } from '@bluehive/random';
- All existing code should “just work”.
Install & Example
npm install @bluehive/random
import { Random } from '@bluehive/random';
const id = Random.id(); // 17-char unique ID
const secret = Random.secret(); // 43-char cryptographically secure secret
const hex = Random.hexString(8); // 8-char hex string
const seeded = Random.createWithSeeds(0);
console.log(seeded.id()); // Deterministic ID (matches Meteor)
Docs, Live Demos, and More
Use Cases
- Drop-in replacement for Meteor’s random utilities (works in Meteor, Fastify, Next.js, Node, browser, etc.)
- Generating session tokens, secrets, test data, API keys, etc.
- Deterministic/random testing with seeds
Feedback, issues, and PRs welcome!
Let me know if you hit any migration snags or want to see more features/examples.
Thanks and happy hacking!