first commit
This commit is contained in:
2
build/node_modules/stable/.npmignore
generated
vendored
Normal file
2
build/node_modules/stable/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
/stable.min.js
|
||||
6
build/node_modules/stable/.travis.yml
generated
vendored
Normal file
6
build/node_modules/stable/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.10
|
||||
notifications:
|
||||
email:
|
||||
- stephan@angrybytes.com
|
||||
79
build/node_modules/stable/README.md
generated
vendored
Normal file
79
build/node_modules/stable/README.md
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
## Stable
|
||||
|
||||
A stable array sort, because `Array#sort()` is not guaranteed stable.
|
||||
|
||||
MIT licensed.
|
||||
|
||||
[](http://travis-ci.org/Two-Screen/stable)
|
||||
|
||||
[](http://ci.testling.com/Two-Screen/stable)
|
||||
|
||||
#### From the browser
|
||||
|
||||
Include [`stable.js`] or the minified version [`stable.min.js`]
|
||||
in your page, then call `stable()`.
|
||||
|
||||
[`stable.js`]: https://raw.github.com/Two-Screen/stable/master/stable.js
|
||||
[`stable.min.js`]: https://raw.github.com/Two-Screen/stable/master/stable.min.js
|
||||
|
||||
#### From Node.js
|
||||
|
||||
Install using NPM:
|
||||
|
||||
npm install stable
|
||||
|
||||
Require in your code:
|
||||
|
||||
var stable = require("stable");
|
||||
|
||||
#### Usage
|
||||
|
||||
The default sort is, as with `Array#sort`, lexicographical:
|
||||
|
||||
stable(["foo", "bar", "baz"]); // => ["bar", "baz", "foo"]
|
||||
stable([10, 1, 5]); // => [1, 10, 5]
|
||||
|
||||
Unlike `Array#sort`, the default sort is **NOT** in-place. To do an in-place
|
||||
sort, use `stable.inplace`, which otherwise works the same:
|
||||
|
||||
var arr = [10, 1, 5];
|
||||
stable(arr) === arr; // => false
|
||||
stable.inplace(arr) === arr; // => true
|
||||
|
||||
A comparator function can be specified:
|
||||
|
||||
// Regular sort() compatible comparator, that returns a number.
|
||||
// This demonstrates the default behavior.
|
||||
function lexCmp(a, b) {
|
||||
return String(a).localeCompare(b);
|
||||
}
|
||||
stable(["foo", "bar", "baz"], lexCmp); // => ["bar", "baz", "foo"]
|
||||
|
||||
// Boolean comparator. Sorts `b` before `a` if true.
|
||||
// This demonstrates a simple way to sort numerically.
|
||||
function greaterThan(a, b) {
|
||||
return a > b;
|
||||
}
|
||||
stable([10, 1, 5], greaterThan); // -> [1, 5, 10]
|
||||
|
||||
#### License
|
||||
|
||||
Copyright (C) 2017 Angry Bytes and contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
23
build/node_modules/stable/bower.json
generated
vendored
Normal file
23
build/node_modules/stable/bower.json
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "stable",
|
||||
"version": "0.1.6",
|
||||
"keywords": ["stable", "array", "sort"],
|
||||
"description": "A stable array sort for JavaScript",
|
||||
"homepage": "https://github.com/Two-Screen/stable",
|
||||
"main": "stable.js",
|
||||
"moduleType": ["globals","node"],
|
||||
"authors": [
|
||||
"Angry Bytes <info@angrybytes.com>",
|
||||
"Stéphan Kochen <stephan@angrybytes.com>",
|
||||
"Domenic Denicola <domenic@domenicdenicola.com>",
|
||||
"Yaffle"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower.json",
|
||||
"package.json",
|
||||
"test.js"
|
||||
]
|
||||
}
|
||||
9
build/node_modules/stable/index.d.ts
generated
vendored
Normal file
9
build/node_modules/stable/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export as namespace stable;
|
||||
export = stable;
|
||||
|
||||
type Comparator<T> = ((a : T, b : T)=>boolean) | ((a: T, b : T)=>number);
|
||||
|
||||
declare function stable<T>(array : T[], comparator? : Comparator<T>) : T[];
|
||||
declare namespace stable {
|
||||
export function inplace<T>(array: T[], comparator? : Comparator<T>) : T[];
|
||||
}
|
||||
88
build/node_modules/stable/package.json
generated
vendored
Normal file
88
build/node_modules/stable/package.json
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"_from": "stable@~0.1.6",
|
||||
"_id": "stable@0.1.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-kQ9dKu17Ugxud3SZwfMuE5/eyxA=",
|
||||
"_location": "/stable",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "stable@~0.1.6",
|
||||
"name": "stable",
|
||||
"escapedName": "stable",
|
||||
"rawSpec": "~0.1.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~0.1.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/imagemin-svgo/svgo"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/stable/-/stable-0.1.6.tgz",
|
||||
"_shasum": "910f5d2aed7b520c6e777499c1f32e139fdecb10",
|
||||
"_spec": "stable@~0.1.6",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/imagemin-svgo/node_modules/svgo",
|
||||
"author": {
|
||||
"name": "Angry Bytes",
|
||||
"email": "info@angrybytes.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Two-Screen/stable/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Stéphan Kochen",
|
||||
"email": "stephan@angrybytes.com"
|
||||
},
|
||||
{
|
||||
"name": "Domenic Denicola",
|
||||
"email": "domenic@domenicdenicola.com"
|
||||
},
|
||||
{
|
||||
"name": "Yaffle"
|
||||
}
|
||||
],
|
||||
"deprecated": false,
|
||||
"description": "A stable array sort for JavaScript",
|
||||
"devDependencies": {
|
||||
"tape": "^4.6.3",
|
||||
"uglify-js": "^2.8.12"
|
||||
},
|
||||
"homepage": "https://github.com/Two-Screen/stable#readme",
|
||||
"keywords": [
|
||||
"stable",
|
||||
"array",
|
||||
"sort"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./stable.js",
|
||||
"name": "stable",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Two-Screen/stable.git"
|
||||
},
|
||||
"scripts": {
|
||||
"minify": "uglifyjs --comments '/^!/' -c -m -o ./stable.min.js ./stable.js",
|
||||
"test": "node ./test.js"
|
||||
},
|
||||
"testling": {
|
||||
"files": "./test.js",
|
||||
"browsers": [
|
||||
"ie6",
|
||||
"ie7",
|
||||
"ie8",
|
||||
"ie9",
|
||||
"ie10",
|
||||
"firefox/25",
|
||||
"chrome/31",
|
||||
"safari/6.0",
|
||||
"opera/12.0",
|
||||
"opera/17.0",
|
||||
"iphone/6.0",
|
||||
"android-browser/4.2"
|
||||
]
|
||||
},
|
||||
"types": "./index.d.ts",
|
||||
"version": "0.1.6"
|
||||
}
|
||||
111
build/node_modules/stable/stable.js
generated
vendored
Normal file
111
build/node_modules/stable/stable.js
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
//! stable.js 0.1.6, https://github.com/Two-Screen/stable
|
||||
//! © 2017 Angry Bytes and contributors. MIT licensed.
|
||||
|
||||
(function() {
|
||||
|
||||
// A stable array sort, because `Array#sort()` is not guaranteed stable.
|
||||
// This is an implementation of merge sort, without recursion.
|
||||
|
||||
var stable = function(arr, comp) {
|
||||
return exec(arr.slice(), comp);
|
||||
};
|
||||
|
||||
stable.inplace = function(arr, comp) {
|
||||
var result = exec(arr, comp);
|
||||
|
||||
// This simply copies back if the result isn't in the original array,
|
||||
// which happens on an odd number of passes.
|
||||
if (result !== arr) {
|
||||
pass(result, null, arr.length, arr);
|
||||
}
|
||||
|
||||
return arr;
|
||||
};
|
||||
|
||||
// Execute the sort using the input array and a second buffer as work space.
|
||||
// Returns one of those two, containing the final result.
|
||||
function exec(arr, comp) {
|
||||
if (typeof(comp) !== 'function') {
|
||||
comp = function(a, b) {
|
||||
return String(a).localeCompare(b);
|
||||
};
|
||||
}
|
||||
|
||||
// Short-circuit when there's nothing to sort.
|
||||
var len = arr.length;
|
||||
if (len <= 1) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
// Rather than dividing input, simply iterate chunks of 1, 2, 4, 8, etc.
|
||||
// Chunks are the size of the left or right hand in merge sort.
|
||||
// Stop when the left-hand covers all of the array.
|
||||
var buffer = new Array(len);
|
||||
for (var chk = 1; chk < len; chk *= 2) {
|
||||
pass(arr, comp, chk, buffer);
|
||||
|
||||
var tmp = arr;
|
||||
arr = buffer;
|
||||
buffer = tmp;
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
// Run a single pass with the given chunk size.
|
||||
var pass = function(arr, comp, chk, result) {
|
||||
var len = arr.length;
|
||||
var i = 0;
|
||||
// Step size / double chunk size.
|
||||
var dbl = chk * 2;
|
||||
// Bounds of the left and right chunks.
|
||||
var l, r, e;
|
||||
// Iterators over the left and right chunk.
|
||||
var li, ri;
|
||||
|
||||
// Iterate over pairs of chunks.
|
||||
for (l = 0; l < len; l += dbl) {
|
||||
r = l + chk;
|
||||
e = r + chk;
|
||||
if (r > len) r = len;
|
||||
if (e > len) e = len;
|
||||
|
||||
// Iterate both chunks in parallel.
|
||||
li = l;
|
||||
ri = r;
|
||||
while (true) {
|
||||
// Compare the chunks.
|
||||
if (li < r && ri < e) {
|
||||
// This works for a regular `sort()` compatible comparator,
|
||||
// but also for a simple comparator like: `a > b`
|
||||
if (comp(arr[li], arr[ri]) <= 0) {
|
||||
result[i++] = arr[li++];
|
||||
}
|
||||
else {
|
||||
result[i++] = arr[ri++];
|
||||
}
|
||||
}
|
||||
// Nothing to compare, just flush what's left.
|
||||
else if (li < r) {
|
||||
result[i++] = arr[li++];
|
||||
}
|
||||
else if (ri < e) {
|
||||
result[i++] = arr[ri++];
|
||||
}
|
||||
// Both iterators are at the chunk ends.
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Export using CommonJS or to the window.
|
||||
if (typeof(module) !== 'undefined') {
|
||||
module.exports = stable;
|
||||
}
|
||||
else {
|
||||
window.stable = stable;
|
||||
}
|
||||
|
||||
})();
|
||||
101
build/node_modules/stable/test.js
generated
vendored
Normal file
101
build/node_modules/stable/test.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
var test = require('tape');
|
||||
var stable = require('./stable.js');
|
||||
|
||||
|
||||
function cmp(a, b) {
|
||||
if (a === b) return 0;
|
||||
if (a > b) return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
function gt(a, b) {
|
||||
return a > b;
|
||||
}
|
||||
|
||||
function diff(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function objCmp(a, b) {
|
||||
return a.x > b.x;
|
||||
}
|
||||
|
||||
test('always returns a new array', function(t) {
|
||||
var array;
|
||||
|
||||
array = [];
|
||||
t.doesNotEqual(array, stable(array));
|
||||
|
||||
array = [1];
|
||||
t.doesNotEqual(array, stable(array));
|
||||
|
||||
array = [1, 2];
|
||||
t.doesNotEqual(array, stable(array));
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('in-place always returns the same array', function(t) {
|
||||
var array;
|
||||
|
||||
array = [];
|
||||
t.equal(array, stable.inplace(array));
|
||||
|
||||
array = [1];
|
||||
t.equal(array, stable.inplace(array));
|
||||
|
||||
array = [1, 2];
|
||||
t.equal(array, stable.inplace(array));
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('basic sorting', function(t) {
|
||||
t.same(
|
||||
stable(["foo", "bar", "baz"]),
|
||||
["bar", "baz", "foo"]
|
||||
);
|
||||
|
||||
t.same(
|
||||
stable([9, 2, 10, 5, 4, 3, 0, 1, 8, 6, 7]),
|
||||
[0, 1, 10, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('comparators', function(t) {
|
||||
t.same(
|
||||
stable([9, 2, 10, 5, 4, 3, 0, 1, 8, 6, 7], cmp),
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
|
||||
t.same(
|
||||
stable([9, 2, 10, 5, 4, 3, 0, 1, 8, 6, 7], gt),
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
|
||||
t.same(
|
||||
stable([9, 2, 10, 5, 4, 3, 0, 1, 8, 6, 7], diff),
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
|
||||
t.same(
|
||||
stable([{x:4}, {x:3}, {x:5}], objCmp),
|
||||
[{x:3}, {x:4}, {x:5}]
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('stable sorting', function(t) {
|
||||
function cmp(a, b) {
|
||||
return a.x > b.x;
|
||||
}
|
||||
t.same(
|
||||
stable([{x:3,y:1}, {x:4,y:2}, {x:3,y:3}, {x:5,y:4}, {x:3,y:5}], cmp),
|
||||
[{x:3,y:1}, {x:3,y:3}, {x:3,y:5}, {x:4,y:2}, {x:5,y:4}]
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user