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

hyperid

v3.2.0

Published

Uber-fast unique id generation, for Node.js and the browser

Downloads

1,518,103

Readme

hyperid

Build Status

Uber-fast unique id generation, for Node.js and the browser. Here are the benchmarks:

crypto.randomUUID x 17,421,022 ops/sec ±1.05% (92 runs sampled)
hashids process.hrtime x 381,775 ops/sec ±0.22% (95 runs sampled)
hashids counter x 730,949 ops/sec ±0.23% (97 runs sampled)
shortid x 34,682 ops/sec ±3.82% (83 runs sampled)
crypto.random x 313,547 ops/sec ±2.88% (82 runs sampled)
nid x 1,365,624 ops/sec ±0.07% (96 runs sampled)
uuid.v4 x 1,313,028 ops/sec ±0.10% (97 runs sampled)
napiRsUuid.v4 x 536,390 ops/sec ±0.20% (96 runs sampled)
uuid.v1 x 1,999,272 ops/sec ±0.09% (98 runs sampled)
nanoid x 3,808,014 ops/sec ±0.33% (95 runs sampled)
hyperid - variable length x 20,197,843 ops/sec ±0.74% (94 runs sampled)
hyperid - fixed length x 18,894,869 ops/sec ±0.12% (95 runs sampled)
hyperid - fixed length, url safe x 20,158,778 ops/sec ±0.54% (94 runs sampled)

Note: Benchmark run with Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz and Node.js v16.3.0

As you can see the native crypto.randomUUID is almost as fast as hyperid on Node.js v16, but not on v14.

Install

npm i hyperid --save

Example

'use strict'

const hyperid = require('hyperid')
const instance = hyperid()

const id = instance()

console.log(id)
console.log(instance())
console.log(hyperid.decode(id))
console.log(hyperid.decode(instance()))

API

hyperid([fixedLength || options])

Returns a function to generate unique ids. The function can accept one of the following parameters:

  • fixedLength: Boolean If fixedLength is true the function will always generate an id that is 33 characters in length, by default fixedLength is false.
  • options: Object If { fixedLength: true } is passed in, the function will always generate an id that is 33 characters in length, by default fixedLength is false. If { urlSafe: true } is passed in, the function will generate url safe ids according to RFC4648. If { startFrom: <int> } is passed in, the first counter will start from that number, which must be between 0 and 2147483647. Fractions are discarded, only the integer part matters.

instance()

Returns an unique id.

instance.uuid

The uuid used to generate the ids, it will change over time. It is regenerated every Math.pow(2, 31) - 1 to keep the integer a SMI (a V8 optimization).

hyperid.decode(id, [options])

Decode the unique id into its two components, a uuid and a counter. If you are generating url safe ids, you must pass { urlSafe: true } as option. It returns:

{
  uuid: '049b7020-c787-41bf-a1d2-a97612c11418',
  count: 1
}

This is aliased as instance.decode.

License

MIT