27 Commits

Author SHA1 Message Date
dependabot[bot]
c6443c2c27 Bump ajv from 6.5.4 to 6.12.6
Bumps [ajv](https://github.com/ajv-validator/ajv) from 6.5.4 to 6.12.6.
- [Release notes](https://github.com/ajv-validator/ajv/releases)
- [Commits](https://github.com/ajv-validator/ajv/compare/v6.5.4...v6.12.6)

---
updated-dependencies:
- dependency-name: ajv
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-11 12:53:32 +00:00
ddfa8632e7 Bump version to 2.0.1 2018-11-19 00:33:25 +00:00
24f4d2af29 Update package-lock.json 2018-11-19 00:32:39 +00:00
3ea2aa4939 Update .npmignore 2018-11-19 00:31:56 +00:00
1751b9930d Merge pull request #9 from jimeh/run-linter-in-travis-ci
Run linter in travis ci
2018-11-18 23:26:43 +00:00
97d3366fb6 Run linter before tests in Travis-CI 2018-11-18 23:23:21 +00:00
62b8f73f82 Have lint script only lint, and lint-fix script lint and fix 2018-11-18 23:22:22 +00:00
1241478006 Fix license field in package.json 2018-11-18 23:12:28 +00:00
0874ee4087 Update copyright 2018-11-18 22:34:19 +00:00
3dbac7b5d4 Merge pull request #8 from jimeh/update-travis-node-versions
Run Node.js versions 10 and 11 to test runs
2018-11-18 22:31:22 +00:00
7e8e25b617 Run Node.js versions 10 and 11 to test runs 2018-11-18 22:26:24 +00:00
a7f443a25f Merge pull request #7 from jimeh/rename-main-methods
Give encode/decode functions more descriptive names
2018-11-18 22:23:59 +00:00
8eaae0b86a Give encode/decode functions more descriptive names
- `encode()`: Renamed to `int_to_base58()`.
- `decode()`: Renamed to `base58_to_int()`.
- Maintain aliases of old function names for backwards compatibility.
2018-11-18 22:17:56 +00:00
35dd6f57a1 Merge pull request #6 from mccanney/backport
Update for newer ES features
2018-11-18 21:37:38 +00:00
David McCanney
2fa51650b8 Update version number
- Update version number to 2.0.0 since changes affect backwards
  compatibility with node v4.
- Update Travis config to allow node module caching.
2018-09-28 23:07:30 +01:00
David McCanney
8fe37d2db5 Update the test configuration
- Add additional node versions for Travis to test.
- Change var to const in mocha JS file.
2018-09-28 22:45:13 +01:00
David McCanney
8aef7a5081 Add package lock file
- Add the package-lock.json file to the repository to ensure consistent
  builds.
2018-09-28 22:25:49 +01:00
David McCanney
39a0f67e35 Update the dependencies versions
- Require node 6 at a minimum to support the newer ES features.  Node
  version functionality determined via https://node.green.
- Update dev dependencies to their latest versions.  Mocha 3.4 relied
  on a version of growl with a known vulnerability.
- Fix the keywords section, this field is actually an array.
- Update eslint syntax to ES6.
2018-09-28 22:00:52 +01:00
David McCanney
deb7b6892c Update the readme
- Change var to const in the usage guidelines.
2018-09-28 21:40:14 +01:00
David McCanney
47c42ff4a5 Update to newer ES features
- Change var to const and let.
- Change arrays to spread syntax.
- Change to arrow functions.
2018-09-28 21:35:26 +01:00
637ec5c6da Merge pull request #5 from jimeh/lint-using-prettier
Lint using prettier
2017-08-20 19:28:40 +01:00
5f6cc4c169 Use prettier for linting and code formatting via eslint 2017-08-20 19:23:27 +01:00
ffc71e6c1a Remove git hooks
While it's a good idea to ensure you don't commit or push anything
broken, I believe that it should come down developer dicipline. Cause
preventing commits if tests or linting fails, can and does get in the
way of legitimate work, specially on non-master branches.
2017-08-20 19:20:27 +01:00
9be24ba511 Merge pull request #4 from jimeh/lint-using-semistandard
Lint using semistandard
2017-07-09 19:46:37 +01:00
51d70572b1 Lint using semistandard 2017-07-09 19:41:48 +01:00
96b27b9505 Clean up test/.eslintrc.js 2017-07-09 19:30:50 +01:00
ed8cbd3fa2 Update Makefile 2017-07-09 19:30:03 +01:00
13 changed files with 1839 additions and 626 deletions

View File

@@ -1,10 +1,14 @@
module.exports = {
extends: 'flickr',
env: {
browser: true,
node: true
},
rules: {}
extends: ["prettier"],
plugins: ["prettier"],
rules: {
"prettier/prettier": "error"
},
parserOptions: {
"ecmaVersion": 6
}
};

View File

@@ -1,2 +1,6 @@
.DS_Store
.eslintrc.js
.travis.yml
Makefile
node_modules
package-lock.json

View File

@@ -1,5 +1,16 @@
language: node_js
cache:
directories:
- node_modules
node_js:
- 4
- 6
- 8
- "node"
- "6"
- "7"
- "8"
- "9"
- "10"
- "11"
script:
- npm run lint
- npm test

View File

@@ -1,4 +1,4 @@
Copyright (c) 2012 Jim Myhrberg.
Copyright (c) 2018 Jim Myhrberg.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -1,22 +1,13 @@
NPM_EXECUTABLE_HOME := node_modules/.bin
PATH := ${NPM_EXECUTABLE_HOME}:${PATH}
hooks: .git/hooks/pre-commit
hooks: .git/hooks/pre-push
.git/hooks/pre-commit: hook.sh
cp $< $@
.git/hooks/pre-push: hook.sh
cp $< $@
publish:
publish: npm-dep
npm publish
test:
test: npm-dep
npm run test
lint:
lint: npm-dep
npm run lint
npm-dep:

View File

@@ -20,9 +20,9 @@ Flickr short URL is: `http://flic.kr/p/brXijP`
## Usage
```javascript
var Base58 = require('base58');
Base58.encode(6857269519); // 'brXijP'
Base58.decode('brXijP'); // 6857269519
const Base58 = require('base58');
Base58.int_to_base58(6857269519); // 'brXijP'
Base58.base58_to_int('brXijP'); // 6857269519
```
## Credit
@@ -34,4 +34,4 @@ name.
## License
Released under the MIT license. Copyright (c) 2012 Jim Myhrberg.
Released under the MIT license. Copyright (c) 2018 Jim Myhrberg.

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -ex
npm run lint
npm run test
node package.json

1167
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,11 @@
{
"name": "base58",
"version": "1.0.1",
"keywords": "base58, flickr",
"description": "Flickr Flavored Base58 Encoding and Decoding",
"licenses": [
{
"type": "MIT",
"url": "https://raw.github.com/jimeh/node-base58/master/LICENSE.md"
}
"version": "2.0.1",
"keywords": [
"base58, flickr"
],
"description": "Flickr Flavored Base58 Encoding and Decoding",
"license": "MIT",
"author": {
"name": "Jim Myhrberg",
"email": "contact@jimeh.me"
@@ -22,15 +19,18 @@
},
"main": "./src/base58",
"engines": {
"node": ">= 4"
"node": ">= 6"
},
"devDependencies": {
"eslint": "^4.1.1",
"eslint-config-flickr": "^1.3.1",
"mocha": "^3.4.2"
"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"
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"test": "mocha"
}
}

View File

@@ -1,33 +1,39 @@
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;
}, {});
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.');
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.');
if (typeof str !== "string") {
throw new Error("Value passed is not a string.");
}
}
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 = '';
var modulus;
exports.int_to_base58 = exports.encode = function(num) {
let str = "";
let modulus;
num = Number(num);
@@ -42,10 +48,10 @@ exports.encode = function (num) {
return alphabet[num] + str;
};
exports.decode = function (str) {
exports.base58_to_int = 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);

View File

@@ -1,6 +1,8 @@
module.exports = {
env: {
mocha: true
mocha: true
},
parserOptions: {
"ecmaVersion": 6
}
};

View File

@@ -1,112 +1,148 @@
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) {
Object.keys(examples).forEach(function(str) {
callback(str, examples[str]);
});
}
describe('Base58', function () {
before(function () {
describe("Base58", function() {
before(function() {
var valid = true;
var count = 0;
exampleRunner(function (str, num) {
exampleRunner(function(str, num) {
count++;
if (typeof str !== 'string') {
if (typeof str !== "string") {
valid = false;
}
if (typeof num !== 'number') {
if (typeof num !== "number") {
valid = false;
}
});
assert.strictEqual(count > 0, true, 'Expected there to be examples');
assert.strictEqual(valid, true, 'Expected the examples to be valid');
assert.strictEqual(count > 0, true, "Expected there to be examples");
assert.strictEqual(valid, true, "Expected the examples to be valid");
});
describe('.encode', function () {
it('encodes number to Base58 string', function () {
exampleRunner(function (str, num) {
assert.strictEqual(base58.encode(num), str);
describe("backwards compatibility", function() {
it(".encode() is an alias to .int_to_base58()", function() {
assert.strictEqual(base58.encode, base58.int_to_base58);
});
it(".decode() is an alias to .base58_to_int()", function() {
assert.strictEqual(base58.decode, base58.base58_to_int);
});
});
describe(".int_to_base58()", function() {
it("encodes number to Base58 string", function() {
exampleRunner(function(str, num) {
assert.strictEqual(base58.int_to_base58(num), str);
});
});
describe('when passed a string only containing numbers', function () {
it('encodes string after first converting it to an integer', function () {
exampleRunner(function (str, num) {
assert.strictEqual(base58.encode(num.toString()), str);
describe("when passed a string only containing numbers", function() {
it("encodes string after first converting it to an integer", function() {
exampleRunner(function(str, num) {
assert.strictEqual(base58.int_to_base58(num.toString()), str);
});
});
});
describe('when passed a non number', function () {
it('throws an error', function () {
assert.throws(function () {
base58.encode('hi');
}, function (err) {
return err.message === 'Value passed is not a non-negative safe integer.';
});
describe("when passed a non number", function() {
it("throws an error", function() {
assert.throws(
function() {
base58.int_to_base58("hi");
},
function(err) {
return (
err.message === "Value passed is not a non-negative safe integer."
);
}
);
});
});
describe('when passed a float', function () {
it('throws an error', function () {
assert.throws(function () {
base58.encode(3.14);
}, function (err) {
return err.message === 'Value passed is not a non-negative safe integer.';
});
describe("when passed a float", function() {
it("throws an error", function() {
assert.throws(
function() {
base58.int_to_base58(3.14);
},
function(err) {
return (
err.message === "Value passed is not a non-negative safe integer."
);
}
);
});
});
describe('when passed a negative number', function () {
it('throws an error', function () {
assert.throws(function () {
base58.encode(-300);
}, function (err) {
return err.message === 'Value passed is not a non-negative safe integer.';
});
describe("when passed a negative number", function() {
it("throws an error", function() {
assert.throws(
function() {
base58.int_to_base58(-300);
},
function(err) {
return (
err.message === "Value passed is not a non-negative safe integer."
);
}
);
});
});
describe('when passed a non-safe integer', function () {
it('throws an error', function () {
assert.throws(function () {
base58.encode(1E100);
}, function (err) {
return err.message === 'Value passed is not a non-negative safe integer.';
});
describe("when passed a non-safe integer", function() {
it("throws an error", function() {
assert.throws(
function() {
base58.int_to_base58(1e100);
},
function(err) {
return (
err.message === "Value passed is not a non-negative safe integer."
);
}
);
});
});
});
describe('.decode', function () {
it('decodes base58 string to number', function () {
exampleRunner(function (str, num) {
assert.strictEqual(base58.decode(str), num);
describe(".base58_to_int()", function() {
it("decodes base58 string to number", function() {
exampleRunner(function(str, num) {
assert.strictEqual(base58.base58_to_int(str), num);
});
});
describe('when passed a non string', function () {
it('throws an error', function () {
assert.throws(function () {
base58.decode(123);
}, function (err) {
return err.message === 'Value passed is not a string.';
});
describe("when passed a non string", function() {
it("throws an error", function() {
assert.throws(
function() {
base58.base58_to_int(123);
},
function(err) {
return err.message === "Value passed is not a string.";
}
);
});
});
describe('when passed a non base58 string', function () {
it('throws an error', function () {
assert.throws(function () {
base58.decode('>_<');
}, function (err) {
return err.message === 'Value passed is not a valid Base58 string.';
});
describe("when passed a non base58 string", function() {
it("throws an error", function() {
assert.throws(
function() {
base58.base58_to_int(">_<");
},
function(err) {
return err.message === "Value passed is not a valid Base58 string.";
}
);
});
});
});

File diff suppressed because it is too large Load Diff