Skip to content

Commit

Permalink
refactor: upgrade code to modern JavaScript (#427)
Browse files Browse the repository at this point in the history
* use let/const instead of var
* use TypedArrays where possible
* performance tweak: use `Date.now()` instead of `new Date.getTime()`
* simplify eslint config
  • Loading branch information
awwit committed May 2, 2020
1 parent 2b79686 commit f6ce4bf
Show file tree
Hide file tree
Showing 18 changed files with 935 additions and 195 deletions.
57 changes: 2 additions & 55 deletions .eslintrc.json
Expand Up @@ -7,65 +7,12 @@
"jest": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"extends": ["eslint:recommended", "standard", "plugin:prettier/recommended"],
"globals": {
"msCrypto": true
},
"parser": "babel-eslint",
"rules": {
"array-bracket-spacing": ["warn", "never"],
"arrow-body-style": ["warn", "as-needed"],
"arrow-spacing": "warn",
"brace-style": ["warn", "1tbs"],
"camelcase": "warn",
"comma-spacing": [
"warn",
{
"after": true
}
],
"dot-notation": "warn",
"eqeqeq": ["warn", "smart"],
"indent": [
"warn",
2,
{
"SwitchCase": 1,
"FunctionDeclaration": {
"parameters": 1
},
"MemberExpression": 1,
"CallExpression": {
"arguments": 1
}
}
],
"key-spacing": [
"warn",
{
"beforeColon": false,
"afterColon": true,
"mode": "minimum"
}
],
"keyword-spacing": "warn",
"no-console": "off",
"no-empty": "off",
"no-multi-spaces": "warn",
"no-redeclare": "off",
"no-restricted-globals": ["warn", "Promise"],
"no-trailing-spaces": "warn",
"no-undef": "error",
"no-unused-vars": [
"warn",
{
"args": "none"
}
],
"one-var": ["warn", "never"],
"padded-blocks": ["warn", "never"],
"react/prop-types": "off",
"react/jsx-no-bind": "off",
"semi": ["warn", "always"]
"no-var": ["error"]
}
}
2 changes: 1 addition & 1 deletion README_js.md
Expand Up @@ -5,7 +5,7 @@ runmd.onRequire = (path) => {
};

// Shim Date and crypto so generated ids are consistent across doc revisions
runmd.Date.prototype.getTime = () => 1551914748172;
runmd.Date.now = () => 1551914748172;

let seed = 0xdefaced;
require('crypto').randomBytes = function () {
Expand Down
4 changes: 3 additions & 1 deletion examples/benchmark/benchmark.js
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-unused-vars
/* global Benchmark:false, uuidv1:false, uuidv3:false, uuidv4:false, uuidv5:false */
const Benchmark = (typeof window !== 'undefined' && window.Benchmark) || require('benchmark');
const uuidv1 = (typeof window !== 'undefined' && window.uuidv1) || require('uuid').v1;
Expand All @@ -9,6 +10,7 @@ console.log('Starting. Tests take ~1 minute to run ...');

const array = new Array(16);
const suite = new Benchmark.Suite();

suite
.add('uuidv1()', function () {
uuidv1();
Expand All @@ -29,7 +31,7 @@ suite
uuidv5('hello.example.com', uuidv5.DNS);
})
.on('cycle', function (event) {
console.log(String(event.target));
console.log(event.target.toString());
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
Expand Down

0 comments on commit f6ce4bf

Please sign in to comment.