npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wa-ulid

v1.0.0

Published

A high-performance ULID (Universally Unique Lexicographically Sortable Identifier) generator using WebAssembly, up to 40x faster than traditional implementations, optimized for backend use.

Downloads

13

Readme

wa-ulid npm version CI/CD

Code of Conduct | Contributing | Changelog

A high-performance ULID (Universally Unique Lexicographically Sortable Identifier) generator using WebAssembly, up to 40x faster than traditional implementations, optimized for backend use.

Features

  • High Performance: Leveraging WebAssembly for significantly faster performance in generating ULIDs.
  • Secure Randomness: Utilizes WebAssembly's cryptographic methods, not requiring external crypto modules.
  • Easy Integration: Fully compatible with ulid's API.

Comparisons with ulid

  • Approximately 40x faster in main ULID generation methods.
  • Maintains all API signatures for seamless migration.
  • Additional initialization step required for WebAssembly module.

Installation

Install using npm:

npm install wa-ulid

Usage

First, initialize the WebAssembly module:

import init, { ulid } from "wa-ulid";

await init();

Then, generate ULIDs:

console.log(ulid());

Seed Time

The ulid function accepts an optional seed time to generate a consistent time-based component:

console.log(ulid(1593045370000));

Monotonic ULIDs

For generating monotonically increasing identifiers:

const ulid = monotonicFactory();
console.log(ulid());
console.log(ulid());

Pseudo-Random Number Generators (PRNG)

While detectPrng is maintained for API compatibility, the random number generation is handled internally by the WebAssembly module and does not utilize the browser or Node.js crypto APIs.

Use Your Own PRNG

This feature allows you to specify your own pseudo-random number generator if needed:

import { factory } from "wa-ulid";
import customPrng from "./myCustomPrng";

const ulid = factory(customPrng);
console.log(ulid());

Considerations

File Size

  • The WebAssembly module increases the file size to approximately 110KB, compared to 4.7KB for ulid.
  • Recommended primarily for backend environments due to the larger file size, though it is fully functional in browsers.

Performance

The benchmarks below demonstrate the significant performance advantage over ulid.

| Function | ulid | wa-ulid | Performance Increase | | ----------------- | ----------------- | ----------------- | -------------------- | | encodeTime | 3,863,741 ops/sec | 4,904,495 ops/sec | 1.27x | | decodeTime | 1,951,730 ops/sec | 5,336,862 ops/sec | 2.73x | | ulid | 44,758 ops/sec | 1,933,859 ops/sec | 43.20x | | monotonicUlid() | 2,382,881 ops/sec | 3,505,757 ops/sec | 1.47x |

These tests were run on an Apple M2 Pro processor, highlighting the efficiency of the WASM-based implementation. You can run benchmarks in your own environment using pnpm benchmark.

License

This project is licensed under the MIT License. See LICENSE for details.