mirror of
https://github.com/jimeh/node-base58.git
synced 2026-02-18 23:26: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"],
|
||||
rules: {
|
||||
"prettier/prettier": "error"
|
||||
},
|
||||
parserOptions: {
|
||||
"ecmaVersion": 6
|
||||
}
|
||||
};
|
||||
|
||||
11
.travis.yml
11
.travis.yml
@@ -1,5 +1,10 @@
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
node_js:
|
||||
- 4
|
||||
- 6
|
||||
- 8
|
||||
- "node"
|
||||
- "6"
|
||||
- "7"
|
||||
- "8"
|
||||
- "9"
|
||||
|
||||
@@ -20,7 +20,7 @@ Flickr short URL is: `http://flic.kr/p/brXijP`
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var Base58 = require('base58');
|
||||
const Base58 = require('base58');
|
||||
Base58.encode(6857269519); // 'brXijP'
|
||||
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",
|
||||
"version": "1.0.1",
|
||||
"keywords": "base58, flickr",
|
||||
"version": "2.0.0",
|
||||
"keywords": [
|
||||
"base58, flickr"
|
||||
],
|
||||
"description": "Flickr Flavored Base58 Encoding and Decoding",
|
||||
"licenses": [
|
||||
{
|
||||
@@ -22,17 +24,17 @@
|
||||
},
|
||||
"main": "./src/base58",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
"node": ">= 6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^4.1.1",
|
||||
"eslint-config-prettier": "^2.3.0",
|
||||
"eslint-plugin-prettier": "^2.2.0",
|
||||
"mocha": "^3.4.2",
|
||||
"prettier": "^1.5.3"
|
||||
"eslint": "^5.6.0",
|
||||
"eslint-config-prettier": "^3.0.0",
|
||||
"eslint-plugin-prettier": "^2.7.0",
|
||||
"mocha": "^5.2.0",
|
||||
"prettier": "^1.14.3"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint . --fix",
|
||||
"test": "mocha test"
|
||||
"test": "mocha"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
|
||||
var base = alphabet.length;
|
||||
const alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
|
||||
const base = alphabet.length;
|
||||
|
||||
// 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;
|
||||
return lookup;
|
||||
}, {});
|
||||
@@ -32,8 +32,8 @@ function assertBase58Character(character) {
|
||||
}
|
||||
|
||||
exports.encode = function(num) {
|
||||
var str = "";
|
||||
var modulus;
|
||||
let str = "";
|
||||
let modulus;
|
||||
|
||||
num = Number(num);
|
||||
|
||||
@@ -51,7 +51,7 @@ exports.encode = function(num) {
|
||||
exports.decode = function(str) {
|
||||
assertString(str);
|
||||
|
||||
return str.split("").reverse().reduce(function(num, character, index) {
|
||||
return [...str].reverse().reduce((num, character, index) => {
|
||||
assertBase58Character(character);
|
||||
return num + alphabetLookup[character] * Math.pow(base, index);
|
||||
}, 0);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
mocha: true
|
||||
},
|
||||
parserOptions: {
|
||||
"ecmaVersion": 6
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var assert = require("assert");
|
||||
var examples = require("./examples");
|
||||
var base58 = require("..");
|
||||
const assert = require("assert");
|
||||
const examples = require("./examples");
|
||||
const base58 = require("..");
|
||||
|
||||
function exampleRunner(callback) {
|
||||
Object.keys(examples).forEach(function(str) {
|
||||
|
||||
Reference in New Issue
Block a user