
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
The any-base npm package allows you to convert numbers between different bases. It supports conversions between any two bases ranging from binary (base 2) to base 62.
Convert from one base to another
This feature allows you to convert a number from one base to another. In this example, a binary number ('1010') is converted to a hexadecimal number ('A').
const anyBase = require('any-base');
const base2ToBase16 = anyBase(anyBase.BIN, anyBase.HEX);
console.log(base2ToBase16('1010')); // Outputs 'A'
Custom base conversion
This feature allows you to define custom bases for conversion. In this example, a decimal number ('255') is converted to a hexadecimal number ('ff') using custom base definitions.
const anyBase = require('any-base');
const customBase = anyBase('0123456789', '0123456789abcdef');
console.log(customBase('255')); // Outputs 'ff'
The base-x package provides a way to encode and decode between various bases. It supports custom alphabets and is highly performant. Compared to any-base, base-x is more focused on performance and flexibility with custom alphabets.
The big-integer package allows for arbitrary-precision arithmetic in JavaScript, including base conversions. It is more comprehensive in terms of mathematical operations compared to any-base, which is specialized in base conversions.
The bignumber.js package provides arbitrary-precision decimal and non-decimal arithmetic. It includes base conversion functionalities but is more focused on precision and mathematical operations, making it more versatile than any-base.
The library allows you to convert any large numbers in any number base to another number base. The base is determined by specifying the alphabet. So is full freedom
npm install any-base --save
converterFunction = anyBase(sourceAlphabet, destinationAlphabet);
Returns function that converts the number of source base to the destination
converterFunction(number)
Returns number of destonation base
var anyBase = require('any-base'),
dec2hex = anyBase(anyBase.DEC, anyBase.HEX),
shortId = anyBase(anyBase.DEC, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+!@#$^'),
longId = anyBase('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+!@#$^', anyBase.DEC);
dec2hex('123456'); // return: '1E240'
shortId('1234567890'); // return: 'PtmIa'
longId('PtmIa'); // return: '1234567890'
FAQs
Converter from any base to other any base
The npm package any-base receives a total of 1,360,685 weekly downloads. As such, any-base popularity was classified as popular.
We found that any-base 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.