Package Exports
- power-radix
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (power-radix) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
power-radix
Library for converting numbers from one radix representation (encoding) to another, with optional custom defined encodings. Inspired by rubyworks/radix.
Features
- Convert to and from any base.
- Define custom encoding and character sets.
Usage
Base conversions with ASCII ordered notations are easy in Javascript.
(255).toString(16) === 'ff'
parseInt('ff', 16) === 255But JavaScript limits you to radix values 2 - 36.
(255).toString(37) // errorpower-radix provides the means of converting to and from any base.
For example, a number in base 256 can be representated by the array [100, 10] (Math.pow(100, 256) + Math.pow(10, 1)) and can be converted to base 10.
// as an array
new PowerRadix([100, 10], 256).toArray(10); // ['2', '5', '6', '1', '0']
// or as a string
new PowerRadix([100, 10], 256).toString(10); // "25610"power-radix also supports custom character encodings. By default, power-radix uses the following character encoding:0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
You can optionally specify an array of characters to use as symbols for a radix to give your output a custom encoding.
var base = ['Q', 'W', 'E', 'R', 'T', 'Y', I', 'O', 'U'];
new PowerRadix([1, 0], 10).toArray(base); // ['W', 'Q']
new PowerRadix('10', 10).toArray(base); // ['W', 'Q']
new PowerRadix(10, 10).toArray(base); // ['W', 'Q']
new PowerRadix([1, 0], 10).toString(base); // "WQ"
new PowerRadix('10', 10).toString(base); // "WQ"
new PowerRadix(10, 10).toString(base); // "WQ"Installing
$ npm install power-radixTesting
// Tests + coverage reports are run using Lab
$ npm test