mirror of
https://github.com/jimeh/node-base58.git
synced 2026-02-19 07:36:40 +00:00
Merge pull request #6 from mccanney/backport
Update for newer ES features
This commit is contained in:
@@ -7,5 +7,8 @@ module.exports = {
|
|||||||
plugins: ["prettier"],
|
plugins: ["prettier"],
|
||||||
rules: {
|
rules: {
|
||||||
"prettier/prettier": "error"
|
"prettier/prettier": "error"
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
"ecmaVersion": 6
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
11
.travis.yml
11
.travis.yml
@@ -1,5 +1,10 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- node_modules
|
||||||
node_js:
|
node_js:
|
||||||
- 4
|
- "node"
|
||||||
- 6
|
- "6"
|
||||||
- 8
|
- "7"
|
||||||
|
- "8"
|
||||||
|
- "9"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ Flickr short URL is: `http://flic.kr/p/brXijP`
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var Base58 = require('base58');
|
const Base58 = require('base58');
|
||||||
Base58.encode(6857269519); // 'brXijP'
|
Base58.encode(6857269519); // 'brXijP'
|
||||||
Base58.decode('brXijP'); // 6857269519
|
Base58.decode('brXijP'); // 6857269519
|
||||||
```
|
```
|
||||||
|
|||||||
1165
package-lock.json
generated
Normal file
1165
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "base58",
|
"name": "base58",
|
||||||
"version": "1.0.1",
|
"version": "2.0.0",
|
||||||
"keywords": "base58, flickr",
|
"keywords": [
|
||||||
|
"base58, flickr"
|
||||||
|
],
|
||||||
"description": "Flickr Flavored Base58 Encoding and Decoding",
|
"description": "Flickr Flavored Base58 Encoding and Decoding",
|
||||||
"licenses": [
|
"licenses": [
|
||||||
{
|
{
|
||||||
@@ -22,17 +24,17 @@
|
|||||||
},
|
},
|
||||||
"main": "./src/base58",
|
"main": "./src/base58",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 4"
|
"node": ">= 6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^4.1.1",
|
"eslint": "^5.6.0",
|
||||||
"eslint-config-prettier": "^2.3.0",
|
"eslint-config-prettier": "^3.0.0",
|
||||||
"eslint-plugin-prettier": "^2.2.0",
|
"eslint-plugin-prettier": "^2.7.0",
|
||||||
"mocha": "^3.4.2",
|
"mocha": "^5.2.0",
|
||||||
"prettier": "^1.5.3"
|
"prettier": "^1.14.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint . --fix",
|
"lint": "eslint . --fix",
|
||||||
"test": "mocha test"
|
"test": "mocha"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
var alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
|
const alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
|
||||||
var base = alphabet.length;
|
const base = alphabet.length;
|
||||||
|
|
||||||
// Create a lookup table to fetch character index
|
// Create a lookup table to fetch character index
|
||||||
var alphabetLookup = alphabet.split("").reduce(function(lookup, char, index) {
|
const alphabetLookup = [...alphabet].reduce((lookup, char, index) => {
|
||||||
lookup[char] = index;
|
lookup[char] = index;
|
||||||
return lookup;
|
return lookup;
|
||||||
}, {});
|
}, {});
|
||||||
@@ -32,8 +32,8 @@ function assertBase58Character(character) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.encode = function(num) {
|
exports.encode = function(num) {
|
||||||
var str = "";
|
let str = "";
|
||||||
var modulus;
|
let modulus;
|
||||||
|
|
||||||
num = Number(num);
|
num = Number(num);
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ exports.encode = function(num) {
|
|||||||
exports.decode = function(str) {
|
exports.decode = function(str) {
|
||||||
assertString(str);
|
assertString(str);
|
||||||
|
|
||||||
return str.split("").reverse().reduce(function(num, character, index) {
|
return [...str].reverse().reduce((num, character, index) => {
|
||||||
assertBase58Character(character);
|
assertBase58Character(character);
|
||||||
return num + alphabetLookup[character] * Math.pow(base, index);
|
return num + alphabetLookup[character] * Math.pow(base, index);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
env: {
|
env: {
|
||||||
mocha: true
|
mocha: true
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
"ecmaVersion": 6
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
var assert = require("assert");
|
const assert = require("assert");
|
||||||
var examples = require("./examples");
|
const examples = require("./examples");
|
||||||
var base58 = require("..");
|
const base58 = require("..");
|
||||||
|
|
||||||
function exampleRunner(callback) {
|
function exampleRunner(callback) {
|
||||||
Object.keys(examples).forEach(function(str) {
|
Object.keys(examples).forEach(function(str) {
|
||||||
|
|||||||
Reference in New Issue
Block a user