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

eyed

v3.0.0

Published

Generates a uuid v4 that is base62 encoded which makes the result compact, and url friendly. Example: `card_3xs3cYSzXKNI5vhHA203qK`

Downloads

53

Readme

Eye-D Test

Generates a uuid v4 that is base62 encoded which makes the result compact, and url friendly. Example: card_3xs3cYSzXKNI5vhHA203qK

The values created are as collision resistent as uuid v4 itself, but should not be considered crytographically secure. Translation: Database ID good. API Key bad.

Installing

npm i eyed

How it works

It has two dependencies: uuid to create the uuid and base-x to base62 encode.

It takes the bytes from a v4 uuid and encodes them to base62 and optionally prefixes it with a human friendly name. Since it's just an encoded uuid you can convert it back to bytes and then even format it as a regular uuid string.

Getting started

import {
  generateUuid,
  generateId,
  parseId,
  validId,
} from 'eyed';

// uuid creates a base62-encoded uuid
console.log(generateUuid()); // unprefixed. just the base62 encoded uuid "3xs3cYSzXKNI5vhHA203qK"

// generateId adds a prefix to uuid with a default separator
console.log(generateId('card')) // card_3xs3cYSzXKNI5vhHA203qK
console.log(generateId('card', ':')) // card:3xs3cYSzXKNI5vhHA203qK

console.log(parseId('card_3xs3cYSzXKNI5vhHA203qK')) // { prefix: 'card', separator: '_', uuid: '3xs3cYSzXKNI5vhHA203qK' }

console.log(validId('card_3xs3cYSzXKNI5vhHA203qK', 'card')) // true
console.log(validId('card_3', 'card')) // true
console.log(validId('card_+', 'card')) // false
console.log(validId('card_3_2', 'card')) // false
// with strict mode the byte length of the id portion of string is confirmed to be 16 bytes
console.log(validId('card_3', 'card', '_', true)) // false

Shorter or longer IDs

It is possible to generate IDs that are either shorter or longer.

Be aware that v4 uuids store data in byte 6 and 8. So if you generate a values that have bytes closer to that, you're really increasing your chances of collisions.

Shorter IDs

In lower volume scenarios all those bytes for a full uuid are probably overkill and you can generate shorter ids like: generateId('c', '_', 10) // c_1yLlrVRrgH2Um7

You can use any value 1-16 for number of bytes. 16 is normal. Going lower than 10 is probably a bad idea unless you know your app can recover from collisions.

Longer IDs

Nothing exists for this out-of-the-box. Your best bet would be to string IDs together: generateId('c', '_') + generateUuid(10) // c_6Qcp3K4umtMQSWnc4T8z8V5COBC7B86UaO2Z

If you don't need the uuid back out, it would be better to generate two shorter ids instead of the one 16 byte and one 10 a above: generateId('c', '_', 13) + generateUuid(13)

The second id would have decreased chances of collisions.