This commit is contained in:
21
node_modules/any-base/LICENSE
generated
vendored
Executable file
21
node_modules/any-base/LICENSE
generated
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Kamil Harasimowicz and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
55
node_modules/any-base/README.md
generated
vendored
Executable file
55
node_modules/any-base/README.md
generated
vendored
Executable file
@@ -0,0 +1,55 @@
|
||||
# README #
|
||||
|
||||
The library allows you to convert any large numbers in any number base to another number base. The base is determined by specifying the alphabet. So is full freedom
|
||||
|
||||
[](https://nodei.co/npm/any-base/)
|
||||
|
||||
## Installation ##
|
||||
|
||||
```
|
||||
npm install any-base --save
|
||||
```
|
||||
|
||||
## API ##
|
||||
|
||||
### AnyBase() ###
|
||||
|
||||
```
|
||||
converterFunction = anyBase(sourceAlphabet, destinationAlphabet);
|
||||
```
|
||||
|
||||
#### Parameters ####
|
||||
|
||||
* {String} __sourceAlphabet__ digits from smallest to the largest
|
||||
* {String} __destinationAlphabet__ digits from smallest to the largest
|
||||
|
||||
#### Return Values ####
|
||||
|
||||
Returns __function__ that converts the number of source base to the destination
|
||||
|
||||
### Convert() ###
|
||||
|
||||
```
|
||||
converterFunction(number)
|
||||
```
|
||||
|
||||
#### Parameters ####
|
||||
|
||||
* {String} __number__ number of source base
|
||||
|
||||
#### Return Values ####
|
||||
|
||||
Returns number of destonation base
|
||||
|
||||
## Example ##
|
||||
|
||||
```js
|
||||
var anyBase = require('any-base'),
|
||||
dec2hex = anyBase(anyBase.DEC, anyBase.HEX),
|
||||
shortId = anyBase(anyBase.DEC, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+!@#$^'),
|
||||
longId = anyBase('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+!@#$^', anyBase.DEC);
|
||||
|
||||
dec2hex('123456'); // return: '1E240'
|
||||
shortId('1234567890'); // return: 'PtmIa'
|
||||
longId('PtmIa'); // return: '1234567890'
|
||||
```
|
||||
30
node_modules/any-base/index.js
generated
vendored
Executable file
30
node_modules/any-base/index.js
generated
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
var Converter = require('./src/converter');
|
||||
|
||||
/**
|
||||
* Function get source and destination alphabet and return convert function
|
||||
*
|
||||
* @param {string|Array} srcAlphabet
|
||||
* @param {string|Array} dstAlphabet
|
||||
*
|
||||
* @returns {function(number|Array)}
|
||||
*/
|
||||
function anyBase(srcAlphabet, dstAlphabet) {
|
||||
var converter = new Converter(srcAlphabet, dstAlphabet);
|
||||
/**
|
||||
* Convert function
|
||||
*
|
||||
* @param {string|Array} number
|
||||
*
|
||||
* @return {string|Array} number
|
||||
*/
|
||||
return function (number) {
|
||||
return converter.convert(number);
|
||||
}
|
||||
};
|
||||
|
||||
anyBase.BIN = '01';
|
||||
anyBase.OCT = '01234567';
|
||||
anyBase.DEC = '0123456789';
|
||||
anyBase.HEX = '0123456789abcdef';
|
||||
|
||||
module.exports = anyBase;
|
||||
40
node_modules/any-base/package.json
generated
vendored
Executable file
40
node_modules/any-base/package.json
generated
vendored
Executable file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "any-base",
|
||||
"version": "1.1.0",
|
||||
"description": "Converter from any base to other any base",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "./node_modules/.bin/watchify . -s AnyBase -o dist/any-base.js -v -d",
|
||||
"build": "./node_modules/.bin/browserify . -s AnyBase | ./node_modules/.bin/uglifyjs -cm > dist/any-base.min.js",
|
||||
"test": "node tests/test.js"
|
||||
},
|
||||
"keywords": [
|
||||
"number",
|
||||
"convert",
|
||||
"base",
|
||||
"alphabet",
|
||||
"short number",
|
||||
"long numbers",
|
||||
"dec",
|
||||
"hex",
|
||||
"bin",
|
||||
"oct",
|
||||
"any"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/HarasimowiczKamil/any-base.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Kamil Harasimowicz",
|
||||
"email": "mifczu@gmail.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"browserify": "^13.1.1",
|
||||
"punycode": "^2.1.0",
|
||||
"uglify-js": "^2.7.4",
|
||||
"watchify": "^3.7.0"
|
||||
}
|
||||
}
|
||||
80
node_modules/any-base/src/converter.js
generated
vendored
Executable file
80
node_modules/any-base/src/converter.js
generated
vendored
Executable file
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Converter
|
||||
*
|
||||
* @param {string|Array} srcAlphabet
|
||||
* @param {string|Array} dstAlphabet
|
||||
* @constructor
|
||||
*/
|
||||
function Converter(srcAlphabet, dstAlphabet) {
|
||||
if (!srcAlphabet || !dstAlphabet || !srcAlphabet.length || !dstAlphabet.length) {
|
||||
throw new Error('Bad alphabet');
|
||||
}
|
||||
this.srcAlphabet = srcAlphabet;
|
||||
this.dstAlphabet = dstAlphabet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert number from source alphabet to destination alphabet
|
||||
*
|
||||
* @param {string|Array} number - number represented as a string or array of points
|
||||
*
|
||||
* @returns {string|Array}
|
||||
*/
|
||||
Converter.prototype.convert = function(number) {
|
||||
var i, divide, newlen,
|
||||
numberMap = {},
|
||||
fromBase = this.srcAlphabet.length,
|
||||
toBase = this.dstAlphabet.length,
|
||||
length = number.length,
|
||||
result = typeof number === 'string' ? '' : [];
|
||||
|
||||
if (!this.isValid(number)) {
|
||||
throw new Error('Number "' + number + '" contains of non-alphabetic digits (' + this.srcAlphabet + ')');
|
||||
}
|
||||
|
||||
if (this.srcAlphabet === this.dstAlphabet) {
|
||||
return number;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
numberMap[i] = this.srcAlphabet.indexOf(number[i]);
|
||||
}
|
||||
do {
|
||||
divide = 0;
|
||||
newlen = 0;
|
||||
for (i = 0; i < length; i++) {
|
||||
divide = divide * fromBase + numberMap[i];
|
||||
if (divide >= toBase) {
|
||||
numberMap[newlen++] = parseInt(divide / toBase, 10);
|
||||
divide = divide % toBase;
|
||||
} else if (newlen > 0) {
|
||||
numberMap[newlen++] = 0;
|
||||
}
|
||||
}
|
||||
length = newlen;
|
||||
result = this.dstAlphabet.slice(divide, divide + 1).concat(result);
|
||||
} while (newlen !== 0);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Valid number with source alphabet
|
||||
*
|
||||
* @param {number} number
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Converter.prototype.isValid = function(number) {
|
||||
var i = 0;
|
||||
for (; i < number.length; ++i) {
|
||||
if (this.srcAlphabet.indexOf(number[i]) === -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = Converter;
|
||||
Reference in New Issue
Block a user