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 🙏

© 2026 – Pkg Stats / Ryan Hefner

foxid

v2.0.0

Published

Compact unique ID generator with support for both ordered timestamp-based and completely random IDs

Readme

foxid

Compact unique ID generator with support for both ordered timestamp-based and completely random IDs. Similar to nanoid.

  • Timestamp-based, reversible back to Date, ordered
  • URL-friendly
  • Cryptographic randomness
  • Simple implementation
  • Good performance
  • Node.js/Deno/Bun and browser support

Now for the nitty-gritty:

This library now (v2) supports two types of IDs: timestamp-based and completely random. Random number generation is done using Node.js's crypto.randomFillSync or the browser's Crypto.getRandomValues depending on the environment.

Timestamp-based IDs are always 13 characters long, while completely random IDs can be any length.

Timestamp-based IDs are encoded as 64 bit unsigned integers, with the most significant 48 bits representing the current timestamp in milliseconds starting from 2000-01-01T00:00:00.000Z, and the remaining 16 bits being completely random.

This provides reasonable BUT not perfect collision resistance. It is reasonably possible to get a collision if you're generating thousands of IDs per millisecond. If you want better collision resistance, it's easy! Just do foxid() + foxid.random() to add 80 extra bits of randomness to your ID.

Also, obviously, you can't represent dates before 2000, or after 10,600.

Finally, timestamp-based IDs are ordered and reversible! Your database's BTree will be so happy. If you stick a bunch of them in an array and call sort() they'll come out in order of generation (as long as they weren't all generated in the same millisecond). And of course, you can reverse them back to Date objects using foxid.reverse().

Here's a few examples:

var foxid = require('foxid');

// Generate a 13 character timestamp-based ID
var id = foxid();
console.log(id); // "02zxqcyyb2tmp"

// Reverse the timestamp-based ID back to Date
console.log(foxid.reverse(id).toISOString()); // "2026-02-10T07:45:51.704Z"

// Generate another timestamp ID with a specific date
var specificID = foxid(new Date('2023-01-01'));
console.log(specificID); // "02mfzm8w01k66"

// Generate a completely random ID, defaults to 16 characters long
var randomID = foxid.random();
console.log(randomID); // "4mwer8wwb7je023t"

// Generate another random ID, 10 characters this time
console.log(foxid(10)); // "7mh99xt5y3"

And of course, here's the full API:

// Generates a random ID with the given length, defaults to 16 characters long
foxid.random = (length?: number) => string;

// Generates a timestamp-based ID with the given date, defaults to current date
foxid.timestamp = (date?: Date) => string;

// Reverses a timestamp-based ID back to Date, explodes if invalid
foxid.reverse = (id: string) => Date;

// Performs either foxid.random(length) or foxid.timestamp(date) based on the option type
// Defaults to foxid.timestamp(new Date())
foxid = (option?: Date | number) => string;

// Note the following aliases, just for fun: foxid.foxid = foxid, foxid.timestamp.reverse = foxid.reverse

License

Licensed under the MIT License.

Made with ❤ by Lua (foxgirl.dev).