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

theshortener

v1.2.0

Published

String Shortener

Readme

CI NPM Publish

theShortener

A fast string shortener that generates short codes using SHA-256 and Base62 encoding, implemented as a native Node.js addon in C++.

Features

  • Fast native C++ implementation (N-API)
  • Configurable output length (1-22 characters, default 8)
  • Async support (genAsync) for non-blocking operation
  • Prebuilt binaries for major platforms (no compiler needed)
  • Cryptographically secure using SHA-256
  • Base62 encoding (0-9, A-Z, a-z)
  • Deterministic results - same input always produces same output
  • ESM and CommonJS support
  • CLI included

Installation

npm install theshortener

Prebuilt binaries are included for Linux, macOS, and Windows. Falls back to compiling from source if no prebuild is available (requires C++ compiler + OpenSSL dev libraries).

Usage

CommonJS

const shortener = require('theshortener');

const code = shortener.gen('https://google.com');
console.log(code); // "Qhq1TQ2n"

// Custom length (1-22)
const short = shortener.gen('https://google.com', 6);
console.log(short); // "Qhq1TQ"

ESM

import { gen, genAsync } from 'theshortener';

const code = gen('https://google.com');

Async

const { genAsync } = require('theshortener');

const code = await genAsync('https://google.com');
console.log(code); // "Qhq1TQ2n"

// Custom length
const long = await genAsync('https://google.com', 16);

TypeScript

import { gen, genAsync } from 'theshortener';

const code: string = gen('https://google.com');
const asyncCode: string = await genAsync('https://google.com', 12);

CLI Usage

Install globally:

npm i -g theshortener

Use from command line:

theshortener https://google.com
# Qhq1TQ2n

theshortener --length 12 https://google.com

theshortener --version
theshortener --help

API

gen(input: string, length?: number): string

Generate a short code synchronously.

  • input — String to shorten (max 64KB)
  • length — Output length, 1-22 (default: 8)
  • returns — Alphanumeric string of the specified length
  • throwsTypeError if input is missing, not a string, or empty; RangeError if input exceeds 64KB or length is out of range

genAsync(input: string, length?: number): Promise<string>

Same as gen() but runs SHA-256 + Base62 encoding in a worker thread.

Development

Prerequisites:

  • Node.js >= 20
  • C++ compiler
  • OpenSSL development libraries

Build from source:

npm run build

Run tests:

npm test

Run benchmarks:

npm run bench

Collision Probability

The default 8-character output uses 64 bits of the SHA-256 hash, providing approximately 47.6 bits of entropy in Base62. By the birthday paradox, you can expect a ~50% collision probability after roughly 2³² (~4.3 billion) unique inputs. For fewer collisions, use a longer output length.

Notes

  • Uses N-API (Node-API) for ABI stability across Node.js versions
  • Uses OpenSSL for SHA-256 hashing
  • This is a one-way hashing implementation. Reverse lookups (getting original string from short code) require storing input-to-code mappings in a database
  • Shorter lengths are prefixes of longer outputs (same input)

License

MIT