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

base-whatever

v2.0.3

Published

A package for encoding and decoding integers and strings using arbitrary bases and digits.

Downloads

52

Readme

base-whatever

An npm package for encoding and decoding integers in arbitrary numeral systems. A numeral system is given as a string of unique UTF-8 characters, which are considered digits in arising order. For example, the decimal system can be specified as "0123456789", and the upper-case hexadecimal as "0123456789ABCDEF". Some basic numeral systems are included in the package through the exported systems object.

The base used for conversions between strings and numbers is taken as the length of the string of digits. Any base ≥ 1 is supported. The first character of the string of digits is considered to be the zero symbol, unless the base is 1 in which case there is no zero symbol but zero is represented as the empty string. This package only operates on integers within the range of integers safely representable by the JS number type, i.e. [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER].

Since all UTF-8 characters are supported, any symbol can be used to represent any digit. For example, one can encode and decode numbers in binary using the thumbs up/down emojis, using the numeral system "👎👍".

One thing this package can be used for is generating all possible strings from a given alphabet, starting from the shortest ones and ensuring all strings generated are unique. This can be achieved by selecting a suitable numeral system and repeatedly encoding increasing integers starting from 0. This could be useful for generating short, human-readable identifiters with arbitrary UTF-8 alphabets. Specifically, the encode method of the Converter class can do this.

A mathematical explanation of the previous paragraph is that the package provides an injective (bijective if no signs or leading zeroes are used in strings) function from the non-negative integers to the strings over an arbitrary alphabet such that the lengths of the strings scale logarithmically with the numbers encoded (unless a unary system is used, in which case the lengths of the strings scale linearly with the size of the numbers encoded).

Installing locally

npm i base-whatever or yarn add base-whatever

Installing globally

npm i -g base-whatever or yarn global add base-whatever

Usage example

import { Converter, systems, encode, decode } from "base-whatever";

// Positive and negative numbers
let converter = new Converter(systems.OCTAL);
console.log(converter.encode(-85)); // "-125"
console.log(converter.encode(85)); // "125"
console.log(converter.decode("125")); // 85
console.log(converter.decode("+125")); // 85
console.log(converter.decode("-125")); // -85

// Zero treatment
converter = new Converter(systems.HEXA_UPPER);
console.log(converter.encode(309)); // "135"
console.log(converter.encode(0)); // "0"
console.log(converter.encode(-0)); // "0"
console.log(converter.decode("0")); // 0
console.log(converter.decode("-0")); // 0
console.log(converter.decode("+0")); // 0
console.log(converter.decode("135")); // 309
console.log(converter.decode("00000135")); // 309
console.log(converter.decode("-00000135")); // -309

// Custom digits
converter = new Converter("012"); // base 3
console.log(converter.encode(12)); // "110"
console.log(converter.decode("110")); // 12

// Unary base
converter = new Converter(systems.UNARY_VERTICAL_BAR);
console.log(converter.encode(16)); // "||||||||||||||||"
console.log(converter.decode("||||||||||||||||")); // 16
console.log(converter.decode("")); // 0

// Using util functions
console.log(encode(systems.BINARY, 32)) // "100000"
console.log(decode(systems.BINARY, "100000")) // 32

API Reference

See the JSDoc comments for a complete API reference.