Socket
Socket
Sign inDemoInstall

any-to-any

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

any-to-any

convert numbers between bases (any base to any base) 🔀 ..


Version published
Weekly downloads
297
decreased by-36.54%
Maintainers
1
Weekly downloads
 
Created
Source

ANY-TO-ANY - converts numbers between bases ; binary , decimal , octal , hexadecimal and muche more ...


imed-jaberi

Build Status    Coverage Status    NPM version    License    Top Language    Code Size    Code of Conduct    PRs Welcome   

The purpose of this module is to convert numbers from any base to other base you want.

This module support both CommonJS and ES Modules.

Limitation

  • Support only bases between 2 and 36.
  • Support only integer numbers.

Next Feature(s)

  • Support float numbers.
  • Add a chainable api (convert().from().to() | convert().from().to().get()).

Installation

# npm
$ npm install any-to-any
# yarn
$ yarn add any-to-any

Usage

This is a practical example of how to use.

// const convert = require('any-to-any')
const { convert } = require("any-to-any");

const inputNumber = "1110111"; // 119 in decimal
const inputBase = 2;
const outputBase = 8;

const result = convert(inputNumber, inputBase, outputBase);
console.log(result);
//  "167"

Also, we have 2 exported methods to convert a value from any base to Decimal (base 10) called fromAnyBaseToDecimalBase and the reverse one from Decimal to any base named fromDecimalBaseToAnyBase.

fromAnyBaseToDecimalBase

// const convert = require('any-to-any')
const { fromAnyBaseToDecimalBase } = require("any-to-any");

const inputNumber = "1110111"; // 119 in decimal
const inputBase = 2;
const result = fromAnyBaseToDecimalBase(inputNumber, inputBase);
console.log(result);
//  "119"

fromDecimalBaseToAnyBase

// const convert = require('any-to-any')
const { fromDecimalBaseToAnyBase } = require("any-to-any");

const inputNumber = "119";
const outputBase = 2;
const result = fromDecimalBaseToAnyBase(inputNumber, outputBase);
console.log(result);
//  "1110111"

NOTE: There are a set of suggested examples that have been tested that you can follow here.

Note about the new experimental convert on v4.2.x

Since we bump to v5.x.x, we remove the new experimental method experimentalConvert because we resolved the problem related to large numbers due to the JS number limitation to handle only 32bit in one shot. We use BigInt for that 🤫.

Please, if you find any problem or you have suggestion to improve the experiance with this module feel free to open an issue.

License

MIT © Imed Jaberi

Keywords

FAQs

Package last updated on 19 Jun 2024

Did you know?

Socket

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.

Install

Related posts

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