Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
base-conversion
Advanced tools
Auto-curried converter between any bases with arbitrary precision support and customisable symbols
Auto-curried converter between any bases with arbitrary precision support and customisable symbols
npm i base-conversion
var bc = require('base-conversion');
var hexToBin = bc(16, 2);
hexToBin('A'); //=> '1010'
hexToBin('1E'); //=> '11110'
See spec.
For any bases above 62, custom symbols are required. See tests for working examples.
var bc = require('base-conversion');
bc.symbols('⓿①②③④⑤⑥⑦⑧⑨ⒶⒷ', 8, 12, '⑦③'); //=> '④Ⓑ'
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'
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'
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'
The default symbols and big implementation are exposed as follows:
bc.defaultSymbols; //=> '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
bc.defaultB; //=> default arbitrary precision implementation (plus, times, div, mod & pow)
FAQs
Auto-curried converter between any bases with arbitrary precision support and customisable symbols
We found that base-conversion demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.