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

@plotdb/suuid

v0.5.1

Published

short uuid with timestamp

Downloads

12

Readme

suuid

short, sortable uuid. convert uuid into base 64 string along with coded timestamp.

Usage

<script src="<path-to>/suuid.bundle.min.js"></script>
<script>
  var id = suuid();
  var ts = suuid.timestamp(id);
  var short = suuid.encode("abc0123");
</script>

sample output ( try with test/gen.ls ):

generated suuid: OTeyNTN4r9fi49Wc5M.AsIMZT0NCe4
timestamp: 1611282605846 ( Fri Jan 22 2021 10:30:05 GMT+0800 (Taipei Standard Time) )

API

  • suuid(opt): randomly return a suuid if opt is omitted. otherwise, opt can be:
    • a base16 string: return encoded corresponding string.
    • an object {id, timestamp}: return an encoded id prefix with timestamp, if timestamp is true.
      • id: a base16 string to encode.
      • timestamp: true if prefix timestamp before encoded id. default true.
  • suuid.timestamp(id): get timestamp ( in epoch unix timestamp ) from given suuid
  • suuid.encode(s): simply encode a base16 string to base64 string ( with our charmap, see below )

Spec

suuid does following things:

  • prefix uuid(v4) with epoch unix timestamp

  • remove separator ( dash ) in uuid.

  • encodes values from hexadecimal to 64-based string with following charmap: ( url-safe chars according to the latest uri spec

    123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0_.

while length of codes corresponding to uuid part are fixed, length of the timestamp code varys. The timestamp bits will be:

  • 7 bytes long before 2109AD
  • 8 bytes long before 10895AD
  • 9 bytes long before 573202AD

and the length of remaining part ( coded uuid, for randomness ) will be always 23 bytes long. thus, to sort suuid before 573202AD, simply add padding zeros before id to make it 32 bytes long.

Comparison

  • uniqid

    • 18 bytes
    • no timestamp
  • ulid

    • 48-bit timestamp + 80-bit entropy
    • base32 encoding, fixed length ( 26 character string. )
      • avoiding similar chars ( like 1IiJj ) and is case insensitive.
    • timestamped ( 1ms precision )
      • overflow after 10889AD
  • ksuid

    • 32-bit timestamp + 128-bit entropy
    • base62 encoding ( 0-9a-zA-Z ), fixed length ( 27 characters string. )
    • timestamped ( 1s precision )
      • offset to start from 2014-03-05
      • overflow after 2150AD
  • @plotdb/suuid

    • varied length timestamp ( 42-bit+ ) + 128-bit entropy
    • base64 encoding ( 0-9a-zA-Z.- ), varied length ( 30 characters + )
    • timestamped ( 1ms precision )
      • unix epoch timestamp ( since 1970-01-01 )
  • uuid v6 proposal

    • TBD
    • try to add timestamp in uuid.
    • just a draft, and was expired.
    • Github Repo

License

MIT