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 🙏

© 2024 – Pkg Stats / Ryan Hefner

base-conversion

v3.3.0

Published

Auto-curried converter between any bases with arbitrary precision support and customisable symbols

Downloads

66

Readme

base-conversion

Build Status Coverage Status Code Climate

Auto-curried converter between any bases with arbitrary precision support and customisable symbols

Install

npm i base-conversion

Basic usage

var bc = require('base-conversion');
var hexToBin = bc(16, 2);

hexToBin('A'); //=> '1010'
hexToBin('1E'); //=> '11110'

See spec.

Custom symbols

For any bases above 62, custom symbols are required. See tests for working examples.

var bc = require('base-conversion');

bc.symbols('⓿①②③④⑤⑥⑦⑧⑨ⒶⒷ', 8, 12, '⑦③'); //=> '④Ⓑ'

Symbol translation

To convert between different sets of symbols, use bc.translate:

var bc = require('base-conversion');
var pipe = require('ramda/src/pipe');

var hexToDuoNormal = bc(16, 12);
var hexToDuoCustom = pipe(hexToDuo, bc.translate('0123456789ᘔƐ'));

hexToDuoNormal('10B'); // => '1A3'
hexToDuoCustom('10B'); // => '1ᘔ3'

To use it to translate from custom symbols, use bc.translateRaw:

var mySymbols = '⓿①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮';
var myTranslate = bc.translateRaw(mySymbols);

var hexToDuoFancy = bc.symbols(mySymbols, 16, 12);
var hexToDuoCustom = pipe(hexToDuoFancy, myTranslate('0123456789ᘔƐ'));

hexToDuoFancy('①⓿⑪'); //=> '①⑩③'
hexToDuoCustom('①⓿⑪'); //=> '1ᘔ3'

Arbitrary precision

var bc = require('base-conversion');
var Big = require('arbitrary-precision')(require('bigjs-adapter'));
var toBigFactory = require('to-decimal-arbitrary-precision');

var d = toBigFactory(Big);

// avoid large numbers to go into exponential notation (adapter dependent)
Big.Impl.E_POS = 50;

bc.big(d, 10, 9, '5678364565345634563456346757364563534534645745');
//=> '802531310452364303450750087576673257456135727727'

// equivalent but it skips a trivial decimal to decimal conversion
bc.fromDecimal.big(d, 9, '5678364565345634563456346757364563534534645745');
//=> '802531310452364303450750087576673257456135727727'

Full raw version

var bc = require('base-conversion');
var Big = require('arbitrary-precision')(require('bigjs-adapter'));
var toBigFactory = require('to-decimal-arbitrary-precision');

var d = toBigFactory(Big);

// avoid large numbers to go into exponential notation (adapter dependent)
Big.Impl.E_POS = 50;

bc.raw(d, '01234#6789', 10, 9, '#678364#6#34#634#634#63467#7364#63#34#3464#74#');
//=> '802#313104#23643034#07#0087#766732#74#613#727727'

// equivalent
bc.fromDecimal.raw(d, '01234#6789', 9, '#678364#6#34#634#634#63467#7364#63#34#3464#74#');
//=> '802#313104#23643034#07#0087#766732#74#613#727727'

Defaults

The default symbols and big implementation are exposed as follows:

bc.defaultSymbols; //=> '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
bc.defaultB; //=> default arbitrary precision implementation (plus, times, div, mod & pow)