1.0.19 • Published 11 months ago

simple-base-converter v1.0.19

Weekly downloads
32
License
MIT
Repository
github
Last release
11 months ago

simple-base-converter

master: npm.io

Simple math module for base conversion.

Install

npm i simple-base-converter

Usage

Some bases(2, 8, 16, 32, 36, 62) are predefined.

  • _10To2(num)
  • _10To8(num)
  • _10To16(num)
  • _10To32(num)
  • _10To36(num)
  • _10To62(num)
  • _2To10(num)
  • _8To10(num)
  • _16To10(num)
  • _32To10(num)
  • _36To10(num)
  • _62To10(num)
import { _10To2, _2To10 } from "simple-base-converter";

_10To2(100); // "1100100"
_2To10(1100100); // "100"

// Input can be both integer or string number.
_10To2("100"); // "1100100"
_2To10("1100100"); // "100"

Of course you can choose bases freely.
convertBase(num, originalBase, newBase) converts num from originalBase to newBase.
If you set integer to originalBase or newBase, they are automatically converted by using default base 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.

import { convertBase } from "simple-base-converter";

convertBase("20a4", 17, 52); // "3Ag"
convertBase("20a4", "0123456789abcdefg", "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"); // "3Ag"

Custom bases are also available.

convertBase(10000, 10, "-・"); // "・--・・・---・----"
convertBase("4649", "0123456789", "零一二三四五六七八九"); // "四六四九"
1.0.19

11 months ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago