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

xksuid

v0.0.4

Published

Extended K-Sortable UID for browser & NodeJS 16+

Downloads

1,968

Readme

Extended K-Sortable UID

This is a browser-friendly implementation of ksuid in JavaScript. The implementation is extended to produce UIDs in descending order, which is beneficial in certain cases, e.g. when used as a key for KV Cloudflare worker storage entries that should be listed in descending order.

Binary keys generated in ascending order per reference KSUID implementation are 20 bytes long, whereas extended KSUIDs are 21 bytes long and are always starting with 61, indicating that timestamp value is calculated as a difference between the maximum possible value (max 32bit unsigned integer) and seconds since 14e8:

# KSUID - Ascending order
   4 bytes           16 bytes
 [ ][ ][ ][ ]  [ ][ ][ ]...[ ][ ][ ]
sec since 14e8        random bytes

# xKSUID - Descending order
1 byte   4 bytes           16 bytes
[ 61 ] [ ][ ][ ][ ]  [ ][ ][ ]...[ ][ ][ ]
 'z'   sec till MAX        random bytes

Text representation for KSUID is 27 characters long, and 28 characters long with xKSUID, starting with z:

# KSUID
24bxFgAT8RPOk01OWecxD8bcLKo

#xKSUID
zYS4GmVK9Hn2JHPota8SAOBQsPgR

Usage

API:

generate() // ASC KSUID
generate(true) // DESC xKSUID
generate(true,new Date('2022-01-01').getTime()) // DESC xKSUID with custom timestamp

Via CDN:

<script>
  import {generate} from 'https://cdn.jsdelivr.net/npm/[email protected]/src/index.js'
</script>

Via NPM:

npm install xksuid

For browser:

import {generate} from 'xksuid'

For NodeJS ESM:

import {generate} from 'xksuid'

For NodeJS CommonJS:

const {generate} = await import('xksuid')

Benchmark

> [email protected] benchmark
> node benchmark.js

8 x Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz

Running 100000 ops

3535.918315887451 ms 35.359183158874515 ns/op 28281.196302155477 ops/sec