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

@thzero/library_id_nanoid

v0.19.1

Published

![GitHub package.json version](https://img.shields.io/github/package-json/v/thzero/library_id_nanoid) ![David](https://img.shields.io/david/thzero/library_id_nanoid) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource

Readme

GitHub package.json version David License: MIT

library_id_nanoid

Id generation for @thzero/library_common, backed by nanoid.

The default — library_common depends on this one directly, so unless an application swaps it out, this is what Utility.generateId() uses. Ids are URL safe, 21 characters long and 16 short, on nanoid's default alphabet.

Requirements

NodeJs

NodeJs version 22+

Installation

NPM

npm install @thzero/library_id_nanoid

Already a dependency of @thzero/library_common; install it explicitly only if you import it directly.

Peer dependencies

None. nanoid is a direct dependency.

What it provides

index.js — default export IdGenerator, a class of statics implementing the generator contract library_common delegates to.

| Member | Behaviour | |---|---| | generateId() | generateLongId() | | generateLongId() | 21 characters, or _lengthLong when set | | generateShortId() | 16 characters, or _lengthShort when set | | setAlphabet(alphabet) | Installs a customAlphabet generator. null restores the default | | setLengthLong(length) / setLengthShort(length) | Set the lengths | | translateToShortId(id) / translateToId(id) | Identity. nanoid ids have no separate short form | | init(alphabet) | Builds and returns a generator — see below |

openSource.js — a default-exported function returning the licence manifest for this package and nanoid, under both the client and server categories, for an application's attribution page.

init does not install anything

IdGenerator.init('AB');          // returns a generator; the class is unchanged
IdGenerator.setAlphabet('AB');   // this is the one that takes effect

init(alphabet) returns customAlphabet(alphabet) and does not assign it to the class, so calling it and expecting later generateId() calls to use that alphabet is a trap the name invites. Use setAlphabet. init is useful only if you want a standalone generator function of your own.

Choosing lengths

Both lengths are a collision trade-off. Read nanoid's collision calculator before changing them or the alphabet — a short alphabet with a short length collides much sooner than the defaults.

Configuration

None. This package reads no configuration. Lengths and alphabet are set through the API above.

Wiring it up

Nothing to do — library_common already uses it. To set an alphabet or lengths:

Utility.setIdGeneratorAlphabet(AppSharedConstants.IdGenerator.alphabet);
Utility.setIdGeneratorLengthLong(24);
Utility.setIdGeneratorLengthShort(8);

On the server these are reached through BootMain's _initIdGeneratorAlphabet, _initIdGeneratorLengthLong and _initIdGeneratorLengthShort hooks:

class AppBootMain extends BootMain {
    _initIdGeneratorAlphabet() {
        return AppSharedConstants.IdGenerator.alphabet;
    }
}

Swapping generators

The other two implementations of the same contract are library_id_shortuuid (uuid v4 with a real 22-character short form) and library_id_uuid (plain uuid v4). Both are drop-in:

import IdGenerator from '@thzero/library_id_shortuuid';

Utility.setIdGenerator(IdGenerator);

Development

npm run lint       # eslint .
npm run lint:fix   # eslint . --fix
npm test           # node --test "test/*.test.js"