Comparing version 3.0.0-1 to 3.0.0
12
index.js
@@ -7,15 +7,15 @@ const DEFAULT_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'; | ||
* Convert a string or number from srcRadix to dstRadix | ||
* @param {string} [inputAlphabet='0123456789abcdef'] alphabet of the input string | ||
* @param {string} [inputAlphabet=DEFAULT_ALPHABET] alphabet of the input string | ||
* @param {string} [outputAlphabet=DEFAULT_ALPHABET] alphabet to buse for the output string | ||
* @returns {(input: string | number, inputBase?: number, outputBase?: number) => string} | ||
*/ | ||
module.exports = function BaseConv(_str = '', inputAlphabet = '0123456789abcdef', outputAlphabet = DEFAULT_ALPHABET) { | ||
function BaseConv(inputAlphabet = DEFAULT_ALPHABET, outputAlphabet = DEFAULT_ALPHABET) { | ||
// char => position map, to avoid calling a O(n) indexOf | ||
const inputAlphabetMap = new Map(Array.from(inputAlphabet, (s, i) => [s, i])); | ||
return (_str = '', inputBase = inputAlphabet.length, outputBase = outputAlphabet.length) => { | ||
return (_str = '', inputBase = 16, outputBase = outputAlphabet.length) => { | ||
if (outputBase > outputAlphabet.length) throw new Error(`Output radix exceeds the outputAlphabet length (${outputAlphabet.length})`); | ||
const res = []; | ||
const str = _str + ''; | ||
const str = `${_str}`; | ||
const s = inputBase <= 36 ? str.toLowerCase() : str; | ||
@@ -50,1 +50,5 @@ let nums = Array.from(s, x => inputAlphabetMap.get(x)); | ||
} | ||
module.exports = BaseConv; | ||
module.exports.conv = module.exports.default = new BaseConv(); |
{ | ||
"name": "base-conv", | ||
"version": "3.0.0-1", | ||
"version": "3.0.0", | ||
"description": "Convert arbitrarily large numbers from any radix representation to any other", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,3 +13,3 @@ # radix conversion | ||
```js | ||
const conv = require('base-conv')(); | ||
const conv = require('base-conv').default; | ||
conv(42, 10, 16) // '2a' | ||
@@ -16,0 +16,0 @@ conv('42', 10, 16) // '2a' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4820
72
0