baichun fb412dddfc 堡垒之夜-工具页 | 6 tahun lalu | |
---|---|---|
.. | ||
benchmark | 6 tahun lalu | |
test | 6 tahun lalu | |
.codeclimate.yml | 6 tahun lalu | |
.eslintignore | 6 tahun lalu | |
.eslintrc | 6 tahun lalu | |
.travis.yml | 6 tahun lalu | |
CODE_OF_CONDUCT.md | 6 tahun lalu | |
CONTRIBUTING.md | 6 tahun lalu | |
LICENSE | 6 tahun lalu | |
Readme.md | 6 tahun lalu | |
base62.js | 6 tahun lalu | |
index.d.ts | 6 tahun lalu | |
package.json | 6 tahun lalu |
A javascript Base62 encode/decoder for node.js
From wikipedia:
Base62 is a priority system to the base 62, which for encoding large numbers using ASCII is character. The digits 0-9 (value 0-9), uppercase letters A-Z (value 10-35) and lowercase letters a-z (value 36-61) are used.
Due to the high number of base formed shorter strings than with the decimal or hexadecimal system , which mainly offers two advantages:
- They can be entered by a human being faster and with a smaller risk of error. In this case, a font should be selected in which characters that can be confused, such as small L and large i, or zero, and large O, are distinguishable.
- Length restrictions, eg when a number is to be used as part of an identifier or file name, can be bypassed. However, it should be noted that the processing system is case-sensitive.
npm install base62
or for yarn:
yarn add base62
Base62 = require('base62')
Base62.encode(999) // 'g7'
Base62.decode('g7') // 999
The default character set is 0-9a-zA-Z
. This can be updated to a custom character set. Naturally, it must be 62 characters long.
Instead of the character set 0-9a-zA-Z
you want to use 0-9A-Za-z
, call the setCharacterSet()
method on the Base62 object passing in the string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
. Note that all characters must be unique.
Base62 = require('base62')
Base62.setCharacterSet("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
Base62.encode(999) // 'G7'
Base62.decode('G7') // 999
Source hosted at GitHub. Report Issues/Feature requests on GitHub Issues.
Copyright (c) 2016 Andrew Nesbitt. See LICENSE for details.