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

@root/uuidv7

v1.0.1

Published

Radically simple (and efficient) UUIDv7 generation for Browsers, Node, Bun, etc (JavaScript)

Downloads

6

Readme

uuidv7

Generate UUID v7 strings, like 019212d3-87f4-7d25-902e-b8d39fe07f08.

uuidv7 > uuidv7.txt
019212d3-87f4-7d25-902e-b8d39fe07f08

| 32-bit time | 16-bit time | 4 ver + 12 rnd | 2 var + 14 rnd | 16 rnd + 32 rnd | | :------------------------: | :---------: | :------------: | :------------: | :----------------------------------------: | | 01 92 12 d3 | 87 f4 | 7d 25 | 90 2e | b8 d3 9f e0 7f 08 |

Table of Contents

Install

Pre-built archives available for Mac, Linux, & Widows.
Compile from source for FreeBSD, OpenBSD, etc.

  1. Download from GitHub Releases: https://github.com/coolaj86/uuidv7/releases
  2. Extract
  3. Place in your PATH
b_triplet='x86_64-linux-musl'
curl -L -O https://github.com/coolaj86/uuidv7/releases/download/v1.0.0/uuidv7-v1.0.0-"$b_triplet".tar.gz
tar xvf ./uuidv7-v1.0.0-"$b_triplet".tar.gz
mv ./uuidv7 ~/bin/

JavaScript Version

Supports both import and require.

Extremely simple implementation that can be tuned for speed or memory efficiency.

npm install --save @root/uuidv7

High-level API:

import UUIDv7 from "@root/uuidv7";

let buffer = new Uint8Array(4096); // optional, if you need lots of UUIDs, and fast
UUIDv7.setBytesBuffer(buffer);

UUIDv7.uuidv7();
// 01922aa4-88ad-7cae-a517-a298a491d35c

UUIDv7.uuidv7Bytes();
// Uint8Array(16) [ 1, 146,  42, 176, 37, 122, 114, 189
//                 172, 240,  1, 146, 42, 176,  37, 122 ]

Low-level API:

let now = Date.now();
let ms64 = BigInt(now);
let bytes = new Uint8Array(16);
let start = 0;
globalThis.crypto.getRandomValues(bytes);

void UUIDv7.fill(bytes, start, ms64);

console.log(bytes);
// Uint8Array(16) [ 1, 146,  42, 176, 37, 122, 114, 189
//                 172, 240,  1, 146, 42, 176,  37, 122 ]
let uuidv7 = UUIDv7.format(bytes);
console.log(uuidv7);
// 01922aa4-88ad-7cae-a517-a298a491d35c

UUIDv7 Spec

By the Characters

There are 36 characters total: 32 hex (0123456789abcdef) + 4 dashes (-)

  8 time    4 time    1v + 3ra   ½v + 3½rb    12 random b
019212d3  -  87f4   -   7d25   -   902e   -   b8d39fe07f08
  • 8ch hex time high
  • -
  • 4ch hex time low
  • -
  • 4ch hex version + "random a"
    • 1ch hex version: 7
    • 3ch hex "random a"
  • -
  • 4ch hex variant + "random b"
    • 1ch hex version: 8, 9, a, b
    • 3ch hex "random b"
  • -
  • 12ch hex randam a
    • 4ch hex random a
    • 8ch hex random a

By the Bits

   48 time         4ver, 12ra   2var, 14rb        random b
019212d3-87f4    -    7d25    -    902e    -    b8d39fe07f08
  • 48 bits of timestamp
    • 32-bit high (minutes to years)
    • 16-bit low (seconds & milliseconds)
  • 16 bits of version + random
    • 4-bit version (0b0111)
    • 12-bit random
  • 64-bits variant + random
    • 2-bit variant (0b10)
    • 62-bit random

Build

See </build.sh>.

Builds with zig v0.13 and the v0.14 previews so far.

curl https://webi.sh/[email protected] | sh
source ~/.config/envman/PATH.env
zig build-exe ./uuidv7.zig -O ReleaseSmall -femit-bin="uuidv7"

for b_target in x86-linux-musl aarch64-macos-none x86_64-windows-gnu; do
    zig build-exe ./uuidv7.zig -O ReleaseSmall \
        -target "${b_target}" -femit-bin="uuidv7-${b_target}"
done

License

Copyright 2024 AJ ONeal [email protected]

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.