occamsrazor
Advanced tools
Comparing version 9.1.3 to 9.1.4
Changelog | ||
9.1.4 (2018/10/17) | ||
================== | ||
- now using stable sort on registry. That makes output more predictable | ||
9.1.3 (2018/02/27) | ||
@@ -4,0 +8,0 @@ ================== |
require('setimmediate') | ||
var validator = require('occamsrazor-validator') | ||
var stable = require('stable') | ||
@@ -78,2 +79,12 @@ function getArgs (a) { | ||
function compare (a, b) { | ||
if (a < b) { | ||
return 1 | ||
} | ||
if (a > b) { | ||
return -1 | ||
} | ||
return 0 | ||
} | ||
// get all adapter that validates with args, with the highest score | ||
@@ -89,3 +100,3 @@ // the result is a single adapter (func, validators) | ||
// sort | ||
results.sort().reverse() | ||
stable.inplace(results, compare) | ||
@@ -105,3 +116,3 @@ if (results.length > 1 && results[0].toString() === results[1].toString()) { | ||
// sort | ||
results.sort().reverse() | ||
stable.inplace(results, compare) | ||
// undecorate | ||
@@ -108,0 +119,0 @@ return undecorate(results) |
{ | ||
"name": "occamsrazor", | ||
"version": "9.1.3", | ||
"version": "9.1.4", | ||
"description": "A plugin system for Javascript", | ||
@@ -10,5 +10,2 @@ "main": "index.js", | ||
"lint": "eslint --fix --ext .js ./ ./tests", | ||
"release:major": "./node_modules/.bin/npm-release major", | ||
"release:minor": "./node_modules/.bin/npm-release minor", | ||
"release:patch": "./node_modules/.bin/npm-release patch", | ||
"precommit": "npm run lint", | ||
@@ -39,3 +36,2 @@ "prepush": "npm run test" | ||
"mocha": "^5.0.0", | ||
"npm-release": "^1.0.0", | ||
"occamsrazor-match": "^4.1.0" | ||
@@ -45,4 +41,5 @@ }, | ||
"occamsrazor-validator": "^9.0.0", | ||
"setimmediate": "^1.0.5" | ||
"setimmediate": "^1.0.5", | ||
"stable": "^0.1.8" | ||
} | ||
} |
@@ -194,1 +194,29 @@ /* eslint-env node, mocha */ | ||
}) | ||
describe('sort stability', function () { | ||
var registry | ||
before(function () { | ||
var isNumber = validator().match(function isNumber (obj) { | ||
return typeof obj === 'number' && !isNaN(obj) | ||
}) | ||
registry = occamsrazor() | ||
.add(isNumber, (a) => a * 1) | ||
.add(isNumber, (a) => a * 2) | ||
.add(isNumber, (a) => a * 3) | ||
.add(isNumber, (a) => a * 4) | ||
.add(isNumber, (a) => a * 5) | ||
.add(isNumber, (a) => a * 6) | ||
.add(isNumber, (a) => a * 7) | ||
.add(isNumber, (a) => a * 8) | ||
.add(isNumber, (a) => a * 9) | ||
.add(isNumber, (a) => a * 10) | ||
.add(isNumber, (a) => a * 11) | ||
}) | ||
it('can be inspected', function () { | ||
var all = registry.all(1) | ||
assert.equal(all.length, 11) | ||
assert.deepEqual(all, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) | ||
}) | ||
}) |
@@ -80,3 +80,3 @@ /* eslint-env node, mocha */ | ||
batch.queue(3) | ||
assert.deepEqual(batch.all(), [12, 4, 13, 9]) | ||
assert.deepEqual(batch.all(), [4, 12, 9, 13]) | ||
}) | ||
@@ -83,0 +83,0 @@ |
@@ -35,7 +35,7 @@ /* eslint-env node, mocha */ | ||
it('proxy should return', function () { | ||
assert.deepEqual(proxy.all('test1'), [2, 1]) | ||
assert.deepEqual(proxy.all('test1'), [1, 2]) | ||
}) | ||
it('adapter should return', function () { | ||
assert.deepEqual(adapter.all('test1'), [2, 1]) | ||
assert.deepEqual(adapter.all('test1'), [1, 2]) | ||
}) | ||
@@ -42,0 +42,0 @@ |
68096
10
1204
3
+ Addedstable@^0.1.8
+ Addedstable@0.1.8(transitive)