# meg-rc

> A simple radix converter.

Latest version **4.0.0** (published 2023-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install meg-rc
pnpm add meg-rc
yarn add meg-rc
bun add meg-rc
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-07-26 |
| First published | 2022-10-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | MegPunyu |
| Maintainers | megpunyu |
| Keywords | radix, base, converter, number, decimal |

## Links

- npm: https://www.npmjs.com/package/meg-rc
- Repository: https://github.com/MegPunyu/meg-rc
- Homepage: https://github.com/MegPunyu/meg-rc#readme
- Issues: https://github.com/MegPunyu/meg-rc/issues
- npm.io page: https://npm.io/package/meg-rc

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2023-07-26
- 3.0.0 — 2023-07-12
- 2.0.7 — 2022-10-13
- 2.0.6 — 2022-10-12
- 2.0.5 — 2022-10-12
- 2.0.4 — 2022-10-12
- 2.0.3 — 2022-10-11
- 2.0.2 — 2022-10-11
- 2.0.1 — 2022-10-10
- 2.0.0 — 2022-10-05

## README

# RadixConverter
A simple radix converter.

## Features
Converts any radix to any radix.

## Installation
```shell
npm install meg-rc
```

## Usage
### decimal <-> base 52
```javascript
import RadixConverter from "meg-rc";

const numerals  = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const converter = new RadixConverter(numerals);

converter.fromDecimal(123456789);  // 8m0Kx
converter.intoDecimal("8m0Kx");    // 123456789
```

### base 7 <-> base 3
```javascript
import RadixConverter from "meg-rc";

const base7 = new RadixConverter("0123456");
const base3 = new RadixConverter("012");

let a = base7.fromDecimal(12345);     // 12345(10) => 50664(7)
let b = base7.convertInto(base3)(a);  // 50664(7) => 121221020(3)
let c = base3.intoDecimal(b);         // 121221020(3) => 12345(10)
```

### base 9 <-> base 4 (variant)
```javascript
import RadixConverter from "meg-rc";

const base9 = new RadixConverter("012345678");
const base4 = new RadixConverter("four");

let a = base9.fromDecimal(6789);      // 6789(10) => 10273(9)
let b = base4.convertFrom(base9)(a);  // 10273(9) => ouuufoo(4)
let c = base4.intoDecimal(b);         // ouuufoo(4) => 6789(10)

base4.intoDecimal("fouuufoo");  // 6789
```

### Reuse of converter (base 6 -> base 8)
```javascript
import RadixConverter from "meg-rc";

const base6 = new RadixConverter("012345");
const base8 = new RadixConverter("01234567");
 
const convert68 = base6.convertInto(base8);  // base 6 => base 8 conversion function
 
let a = base6.fromDecimal(1357);  // 1357(10) => 10141(6)
let b = base6.fromDecimal(2468);  // 2468(10) => 15232(6)
 
a = convert68(a);  // 10141(6) => 2515(8)
b = convert68(b);  // 15232(6) => 4644(8)
 
base8.intoDecimal(a);  // 2515(8) => 1357(10)
base8.intoDecimal(b);  // 4644(8) => 2468(10)
```

### Use multiple characters as one numeral
```javascript
import RadixConverter from "meg-rc";

// pass numerals as array
const converter = new RadixConverter(["ba", "bana", "banana"]);

let a = converter.fromDecimal(123);  // banabanabanabananaba
let b = converter.intoDecimal(a);    // 123
```

### Use Emoji
```javascript
import RadixConverter from "meg-rc";

// these emoji are made up of multiple characters
const converter = new RadixConverter(["🧑", "🧑🏻", "🧑🏼", "🧑🏽", "🧑🏾", "🧑🏿"]);

let a = converter.fromDecimal(11190);  // 🧑🏻🧑🏼🧑🏽🧑🏾🧑🏿🧑
let b = converter.intoDecimal(a);      // 11190
```

### Disable validation
```javascript
import RadixConverter from "meg-rc";

// validation disabled (nothing happens)
new RadixConverter(["1", "2", "12"], false);

// validation enabled (throws TypeError)
// Invalid numerals: 12 and 2 cannot be used together 
new RadixConverter(["1", "2", "12"]);
```

---
_Source: https://npm.io/package/meg-rc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
