Use prettier for linting and code formatting via eslint

This commit is contained in:
2017-07-09 19:41:48 +01:00
parent ffc71e6c1a
commit 5f6cc4c169
5 changed files with 618 additions and 580 deletions

View File

@@ -1,32 +1,38 @@
var alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
var alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
var base = alphabet.length;
// Create a lookup table to fetch character index
var alphabetLookup = alphabet.split('').reduce(function (lookup, char, index) {
var alphabetLookup = alphabet.split("").reduce(function(lookup, char, index) {
lookup[char] = index;
return lookup;
}, {});
function assertNonNegativeSafeInteger (val) {
if (typeof val !== 'number' || isNaN(val) || val < 0 || val > Number.MAX_SAFE_INTEGER || Math.floor(val) !== val) {
throw new Error('Value passed is not a non-negative safe integer.');
function assertNonNegativeSafeInteger(val) {
if (
typeof val !== "number" ||
isNaN(val) ||
val < 0 ||
val > Number.MAX_SAFE_INTEGER ||
Math.floor(val) !== val
) {
throw new Error("Value passed is not a non-negative safe integer.");
}
}
function assertString (str) {
if (typeof str !== 'string') {
throw new Error('Value passed is not a string.');
function assertString(str) {
if (typeof str !== "string") {
throw new Error("Value passed is not a string.");
}
}
function assertBase58Character (character) {
function assertBase58Character(character) {
if (alphabetLookup[character] === undefined) {
throw new Error('Value passed is not a valid Base58 string.');
throw new Error("Value passed is not a valid Base58 string.");
}
}
exports.encode = function (num) {
var str = '';
exports.encode = function(num) {
var str = "";
var modulus;
num = Number(num);
@@ -42,10 +48,10 @@ exports.encode = function (num) {
return alphabet[num] + str;
};
exports.decode = function (str) {
exports.decode = function(str) {
assertString(str);
return str.split('').reverse().reduce(function (num, character, index) {
return str.split("").reverse().reduce(function(num, character, index) {
assertBase58Character(character);
return num + alphabetLookup[character] * Math.pow(base, index);
}, 0);