Code Monkey home page Code Monkey logo

charcoder's Introduction

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"

charcoder's People

Contributors

robojones avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.