1.0.0 • Published 10 years ago

radixer v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

radixer

NPM version Build status Downloads

This package lets you convert a big number like 123456789 to a short string like 7MyqL, and back again.

You can do the same thing natively with .toString() and parseInt(), but only up to a radix of 36 (using the 26 letters a-z and the 10 digits 0-9). This package uses a larger character set (including A-Z, - and _, totalling 64), so you get shorter strings that are still URL-friendly.

Basic usage

var radixer = require('radixer');

radixer.numberToString(12345678); // l65E
radixer.numberToString('l65E'); // 12345678

The default radixer uses the following 64 characters:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_

Alternative API

Use the module as a constructor to get a custom radixer, using whatever character set you want.

The more characters you provide, the shorter your strings will be.

var Radixer = require('radixer');

var radixer = new Radixer('àêīöû!@%$^&*;[]'); // 15 chars

radixer.numberToString(12345); // ö^[à
radixer.stringToNumber('ö^[à'); // 12345

Licence

MIT