1.1.9 • Published 7 years ago

charcoder v1.1.9

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

charcoder

Convert numbers into different numeral systems and back

Build Status Test Coverage

bitHound Code bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies License: MIT

Installation

npm i charcoder --save

Usage

Hexadecimal (0-9, a-f)

const Charcoder = require('charcoder')

const hex = new Charcoder()

hex.encode(100) // '64'
hex.decode('64') // 100

Duosexagesimal (0-9, a-f, A-F)

const {
  Charcoder,
  B62
} = require('charcoder')

const b62 = new Charcoder(B62)

b62.encode(100) // '1C'
b62.decode('1C') // 100

Custom

You can use any characters to create your own numeral system. For example -, + and the word hey.

const Charcoder = require('charcode')

const custom = new Charcoder('-' + '+' + 'hey')

custom.encode(100) // 'y--'
custom.decode('y--') // 100

Class: Charcoder

const Charcoder = require('charcoder')
// or
const { Charcoder } = require('charcoder')

constructor(charset)

  • charset <String> string that includes the characters of your numeral system. (default: Charcoder.HEX)
a = new Charcoder('hi' + 'baz')

a.charset // 'hibaz'

Warning: Make sure that each character appears only once!

#encode(number)

  • number <Number> number to convert

returns a string representing the number in the numeral system of the Charcoder.

#decode(string)

  • string <String> string to convert

returns a number representing the value of the given string.

.NUM

A string that includes the numbers from 0 to 10.

Charcoder.NUM // "0123456789"

.ABC

The whole alphabet in lowercase.

Charcoder.ABC // "abcdefghijklmnopqrstuvwxyz"

.HEX

All characters of the hexadecimal system (0-9, a-f).

Charcoder.HEX // "0123456789abcdef"

.B62

All characters of the duosexagesimal system (0-9, a-f, A-F). The system consists of 62 characters.

Charcoder.B62 // "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago