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

youtube-like-id

v1.0.4

Published

Generate YouTube-style short IDs from numbers. Lightweight, fast, and reversible base62 encoder with optional obfuscation.

Readme

YouTubeID for TypeScript

Generate YouTube-style short IDs from numbers. Lightweight, fast, and reversible base62 encoder with optional obfuscation.

npm version Node.js 18+ License: MIT TypeScript

Other programming languages

Features

  • Lightweight - Zero dependencies, pure TypeScript
  • Fast - Simple base62 encoding/decoding
  • Reversible - Encode and decode without data loss
  • Obfuscation - Optional secure key to shuffle the dictionary
  • Type-safe - Full TypeScript support with strict types
  • Universal - Works in Node.js and browsers (ESM + CJS)

Installation

npm install youtube-like-id

Or with yarn/pnpm:

yarn add youtube-like-id
pnpm add youtube-like-id

Quick Start

import { toAlphanumeric, toNumeric } from 'youtube-like-id';

// Encode a number to a short string
toAlphanumeric(12345);  // -> 'dnh'

// Decode back to number
toNumeric('dnh');  // -> 12345

Usage

Basic Encoding/Decoding

import { toAlphanumeric, toNumeric } from 'youtube-like-id';

// Number to alphanumeric
toAlphanumeric(0);        // -> 'a'
toAlphanumeric(61);       // -> 'Z'
toAlphanumeric(62);       // -> 'ba'
toAlphanumeric(12345);    // -> 'dnh'
toAlphanumeric(999999);   // -> 'eGGf'

// Alphanumeric to number
toNumeric('dnh');         // -> 12345

With Secure Key (Obfuscation)

Use a secure key to shuffle the dictionary, making IDs harder to predict:

import { toAlphanumeric, toNumeric } from 'youtube-like-id';

// Without key
toAlphanumeric(12345);                          // -> 'dnh'

// With secure key (different output)
toAlphanumeric(12345, { secureKey: 'secret' }); // -> 'UDJ'

// Decode with the same key
toNumeric('UDJ', { secureKey: 'secret' });      // -> 12345

Case Transformation

import { toAlphanumeric, Transform } from 'youtube-like-id';

toAlphanumeric(12345, { transform: Transform.UPPER });  // -> 'DNH'
toAlphanumeric(12345, { transform: Transform.LOWER });  // -> 'dnh'

Encoder Factory

For repeated operations with the same settings, use the Encoder class:

import { create, Transform } from 'youtube-like-id';

// Create encoder with preset options
const enc = create({ secureKey: 'my-secret', transform: Transform.UPPER });

// Encode
enc.encode(12345);      // -> 'HQJ' (transformed for display)
enc.encodeRaw(12345);   // -> 'hqj' (raw for storage/decoding)

// Decode
enc.decode('hqj');      // -> 12345

API Reference

Functions

toAlphanumeric(number, options?)

Convert a number to a short alphanumeric string.

| Parameter | Type | Default | Description | |---------------------|-------------|----------|---------------------------| | number | number | required | The number to convert | | options.padUp | number | 0 | Padding value | | options.secureKey | string | - | Key to shuffle dictionary | | options.transform | Transform | NONE | Case transformation |

toNumeric(alphanumeric, options?)

Convert an alphanumeric string back to a number.

| Parameter | Type | Default | Description | |---------------------|----------|----------|-------------------------------------| | alphanumeric | string | required | The string to convert | | options.padUp | number | 0 | Padding value (must match encoding) | | options.secureKey | string | - | Key (must match encoding) |

create(options?)

Create a reusable Encoder instance with preset options.

Classes

Encoder

Reusable encoder with preset options.

  • encode(number) - Convert number to alphanumeric (with transform)
  • encodeRaw(number) - Convert number to alphanumeric (without transform)
  • decode(alphanumeric) - Convert alphanumeric to number

Transform

Enum for case transformation:

  • Transform.NONE - No transformation
  • Transform.UPPER - Uppercase output
  • Transform.LOWER - Lowercase output

Types

interface ConvertOptions {
  padUp?: number;
  secureKey?: string;
  transform?: Transform;
}

Use Cases

  • URL shorteners - Convert database IDs to short URLs
  • Public IDs - Hide sequential database IDs from users
  • Share codes - Generate readable codes for sharing
  • Invite links - Create short invitation tokens

Performance

The library uses base62 encoding (a-z, 0-9, A-Z) which provides:

| Number Range | Output Length | |----------------------|---------------| | 0 - 61 | 1 character | | 62 - 3,843 | 2 characters | | 3,844 - 238,327 | 3 characters | | 238,328 - 14,776,335 | 4 characters |

Contributing

Contributions are welcome! Please read our Contributing Guidelines and Code of Conduct.

# Clone and setup
git clone https://github.com/wow-apps/youtube-id-ts.git
cd youtube-id-ts
npm install

# Run tests
npm test

# Build
npm run build

Credits

A TypeScript port of the YouTube-style ID generator originally created by Kevin van Zonneveld and contributors.

License

MIT © Oleksii Samara, Kevin van Zonneveld