bases.js

Utility for converting numbers to/from different bases/alphabets.

  • 所有者: aseemk/bases.js
  • 平台:
  • 许可证:
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Build Status

bases.js

Utility for converting numbers to/from different bases/alphabets.
Common bases have convenience aliases (see below), but arbitrary/custom
alphabets can be used.

Installation

On the server side w/ Node.js:

npm install bases

Or in the browser (adds a global Bases variable for now):

<script src="bases.js"></script>

Usage

var bases = require('./bases');
  // or window.Bases in the browser

bases.toBase16(200);                // => 'c8'
bases.toBase62(99999);              // => 'q0T'
bases.toAlphabet(300, 'aAbBcC');    // => 'Abba'

bases.fromBase16('c8');               // => 200
bases.fromBase62('q0T');              // => 99999
bases.fromAlphabet('Abba', 'aAbBcC'); // => 300

API

Going from numbers to strings:

  • toAlphabet(num, alphabet): returns a string representation of the given
    number for the given alphabet, where the alphabet is an arbitrary string of
    characters. (See known alphabets below for examples.)

  • toBase(num, base): convenience helper for known bases (see below).

  • toBaseX(num): convenience helpers for known bases (see below), e.g.
    toBase62(num).

Going from strings to numbers:

  • fromAlphabet(str, alphabet): returns an integer representation of the given
    string for the given alphabet.

  • fromBase(num, base): convenience helper for known bases.

  • fromBaseX(str): convenience helpers for known bases.

Known Bases/Alphabets

Numbers only:

Letters only:

Alphanumeric:

Human-friendly:

Other:

Base-64 warning: besides there being several different standards, padding isn't currently added and line lengths aren't tracked. Not recommended for use with APIs that expect formal base-64 strings!

License

MIT license. (c) 2012-2014 Aseem Kishore
and contributors.

主要指标

概览
名称与所有者aseemk/bases.js
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证
所有者活动
创建于2012-07-16 20:33:26
推送于2019-05-30 14:23:32
最后一次提交2014-05-31 11:43:04
发布数2
最新版本名称0.2.0 (发布于 )
第一版名称0.1 (发布于 2012-07-16 16:35:54)
用户参与
星数44
关注者数4
派生数9
提交数29
已启用问题?
问题数7
打开的问题数6
拉请求数3
打开的拉请求数2
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?