Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

base-conv

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-conv - npm Package Compare versions

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'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc