Comparing version 1.0.4 to 1.0.5
@@ -1,37 +0,1 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
const OFFSET = 32; | ||
const BASE = 65535 - OFFSET; | ||
let alphabet = []; | ||
for (let i = 0; i < BASE; i++) { | ||
alphabet.push(String.fromCharCode(i + OFFSET)); | ||
} | ||
const encode = exports.encode = num => { | ||
if (!/^\d+$/.test(num)) throw new Error('Value passed is not an int') | ||
if (typeof num !== 'number') num = ~num; | ||
const base = alphabet.length; | ||
let str = ''; | ||
while (num >= base) { | ||
const mod = num % base; | ||
str = alphabet[mod] + str; | ||
num = (num - mod) / base; | ||
} | ||
return alphabet[num] + str | ||
}; | ||
const decode = exports.decode = str => { | ||
let num = 0; | ||
while (str) { | ||
let pos = str[0].charCodeAt(0) - OFFSET; | ||
if (pos < 0) throw new Error(`Can't find ${str[0]}`) | ||
let powerOf = str.length - 1; | ||
num += pos * (Math.pow(BASE, powerOf)); | ||
str = str.substring(1); | ||
} | ||
return num | ||
}; | ||
}))); | ||
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b(a['base-65503']={})})(this,function(a){'use strict';for(var b=32,c=65535-b,d=[],e=0;e<c;e++)d.push(String.fromCharCode(e+b));a.encode=function(a){if(!/^\d+$/.test(a))throw new Error('Value passed is not an int');'number'!=typeof a&&(a=~a);for(var b=d.length,c='';a>=b;){var e=a%b;c=d[e]+c,a=(a-e)/b}return d[a]+c},a.decode=function(a){for(var d=0;a;){var e=a[0].charCodeAt(0)-b;if(0>e)throw new Error('Can\'t find '+a[0]);var f=a.length-1;d+=e*Math.pow(c,f),a=a.substring(1)}return d},Object.defineProperty(a,'__esModule',{value:!0})}); |
{ | ||
"name": "base-65503", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Base 65503 encoder & decoder for numbers", | ||
"main": "lib/index.js", | ||
"module": "lib/index.mjs", | ||
"repository": "https://github.com/wopian/base-65503.git", | ||
@@ -26,5 +27,9 @@ "bugs": "https://github.com/wopian/base-65503/issues", | ||
"test": "jest --coverage", | ||
"build": "rollup -c --environment BUILD:production" | ||
"build": "cross-env NODE_ENV=production rollup -c --environment BUILD:production" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^7.2.3", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.6.0", | ||
"cross-env": "^5.0.1", | ||
"eslint": "^4.3.0", | ||
@@ -34,2 +39,4 @@ "eslint-plugin-jest": "^20.0.3", | ||
"rollup": "^0.45.2", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-babili": "^3.1.0", | ||
"rollup-plugin-cleanup": "^1.0.1", | ||
@@ -36,0 +43,0 @@ "standard": "^10.0.2" |
Sorry, the diff of this file is not supported yet
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3848
12
5
1