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 🙏

© 2025 – Pkg Stats / Ryan Hefner

basex-converter

v1.0.1

Published

Decode/encode hex,binary,regular values in any base and Base Converter

Readme

basex-converter

NPM Package NPM License npm bundle size NPM Download

Due to the limitation of JavaScript's integer representation, which is limited to 53 bits, handling large numbers for encryption tasks can be challenging. Existing libraries run into problems when dealing with such values;
To fix this limitation, This library provides encoding of large numbers. This library provides the following features:

Encoding and decoding of various data types:

  • Regular numerical values
  • Hexadecimal values
  • Binary data as Uint8Array Base Conversion: This library provides a multipurpose convert_base() function that can convert a value from any base to another base without rounding off and size restriction

By overcoming JavaScript's integer limitations, this library allows developers to efficiently work with large numbers in encoding and base conversion tasks.

[!CAUTION]
Be careful, spaces(" ") in the whole value and zeros(0) at the beginning of the value being ignored

Default alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Inverted alphabet: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Default base: 62

Alphabets

See below for a list of commonly recognized alphabets, and their respective base.

| Base | Import Name | Alphabet | |:----:|:------------------------|-----------------------------------------------------------------------| | 2 | ALPHABET_BASE2 | 01 | | 8 | ALPHABET_BASE8 | 01234567 | | 11 | ALPHABET_BASE11 | 0123456789a | | 16 | ALPHABET_BASE16 | 0123456789abcdef | | 32 | ALPHABET_BASE32 | 0123456789ABCDEFGHJKMNPQRSTVWXYZ | | 36 | ALPHABET_BASE36 | 0123456789abcdefghijklmnopqrstuvwxyz | | 58 | ALPHABET_BASE58 | 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz | | 62 | ALPHABET_BASE62_Default | 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ | | 64 | ALPHABET_BASE64 | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ | | 67 | ALPHABET_BASE67 | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~ |

Getting started

Installation

npm install basex-converter

Alternatively using Yarn:

yarn add basex-converter

Usage

Import

import base62 from 'basex-converter';
// or for making instance with custom alphabet
import { Base62, ALPHABET_BASE62_Default, ALPHABET_BASE62_INVERTED, BASE_DEFAULT } from 'basex-converter';

Commonjs require

const base62 = require('basex-converter').default;
const { Base62, ALPHABET_BASE62_Default, ALPHABET_BASE62_INVERTED, BASE_DEFAULT } = require('basex-converter');
console.log(base62.decode('base62'));
// '34441886726'
console.log(base62.encode('34441886726'));
// 'base62'

Encode and decode bytes

console.log(base62.encode_bytes(new Uint8Array([0x01, 0x01])));
// '49'
console.log(base62.decode_bytes('49'));
// Uint8Array(2) [ 1, 1 ]

Encode and decode hex

This function is useful to encode and decode MongoDB ObjectId too

console.log(base62.encode_hex('604a38563'));
// 'SDG16R'
console.log(base62.decode_hex('SDG16R'));
// '604a38563'

// encode and decode mongodb objectid
console.log(base62.encode_hex('63d91de18f092ab964484b9e'));
// 'eBhQNIyMqR6WH3XS'
console.log(base62.decode_hex('eBhQNIyMqR6WH3XS'));
// '63d91de18f092ab964484b9e'

Base converter

This function is able to convert any base to another with no limit on the size of value

console.log(base62.convert_base('ff', 16, 10));
// '255'
console.log(base62.convert_base('wiv', 36, 10));
// '42151'
console.log(base62.convert_base('123456789123456789123456789123456789123456789', 10, 16));
// '58936e53d139afefabb2683f150b684045f15'

This library provides the ability to change the alphabet and base for encoding and decoding. However, changing the base is not recommended unless you are sure that the chosen base works without malfunctioning.
But the alphabet can be changed without functional problems. it just sensitive to "space" character, and we can not use it.

import { Base62, ALPHABET_BASE58 } from 'basex-converter';
// make instance
const base62 = new Base62();
// make another base
const base62 = new Base62(ALPHABET_BASE58, 58);
// or you can set alphabet
const base62 = new Base62('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
// or base
const base62 = new Base62('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 62);

Can pass custom alphabet for each converting

console.log(base62.decode('base62', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'));
// '34441886726'
console.log(base62.encode('34441886726', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'));
// 'base62'

Change alphabet or base, for changing base you should set a compatible alphabet too

import base62, { ALPHABET_BASE58, ALPHABET_BASE62_INVERTED } from 'basex-converter';
// use costom alphabet
base62.setAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
// or use existing ones
base62.setAlphabet(ALPHABET_BASE62_INVERTED);
base62.setBaseAlphabet(ALPHABET_BASE58, 58);