Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.

Commit 5e16583

Browse files
author
Stéphan Kochen
committed
Update dependencies
1 parent ce0ec3d commit 5e16583

File tree

4 files changed

+95
-94
lines changed

4 files changed

+95
-94
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"index.d.ts"
2222
],
2323
"devDependencies": {
24-
"rollup": "^0.50.0",
24+
"rollup": "^0.57.1",
2525
"tape": "^4.6.3",
26-
"uglify-js": "^2.8.12"
26+
"uglify-js": "^3.3.21"
2727
},
2828
"scripts": {
2929
"test": "node ./test.js",

rollup.config.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
var fs = require('fs');
2-
var pkg = require('./package.json');
1+
const fs = require('fs');
2+
const pkg = require('./package.json');
33

4-
var banner = fs.readFileSync('./src/banner.js', 'utf8')
4+
const banner = fs.readFileSync('./src/banner.js', 'utf8')
55
.replace('${version}', pkg.version);
66

77
module.exports = {
88
input: './src/stable.js',
99
output: [{
10+
banner,
1011
file: pkg.main,
11-
format: 'umd'
12+
format: 'umd',
13+
name: 'stable'
1214
}, {
15+
banner,
1316
file: pkg.module,
1417
format: 'es'
15-
}],
16-
name: 'stable',
17-
banner: banner
18+
}]
1819
};

stable.js

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,108 +2,108 @@
22
//! © 2017 Angry Bytes and contributors. MIT licensed.
33

44
(function (global, factory) {
5-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
6-
typeof define === 'function' && define.amd ? define(factory) :
7-
(global.stable = factory());
5+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
6+
typeof define === 'function' && define.amd ? define(factory) :
7+
(global.stable = factory());
88
}(this, (function () { 'use strict';
99

10-
// A stable array sort, because `Array#sort()` is not guaranteed stable.
11-
// This is an implementation of merge sort, without recursion.
10+
// A stable array sort, because `Array#sort()` is not guaranteed stable.
11+
// This is an implementation of merge sort, without recursion.
1212

13-
var stable = function(arr, comp) {
14-
return exec(arr.slice(), comp);
15-
};
13+
var stable = function(arr, comp) {
14+
return exec(arr.slice(), comp);
15+
};
1616

17-
stable.inplace = function(arr, comp) {
18-
var result = exec(arr, comp);
17+
stable.inplace = function(arr, comp) {
18+
var result = exec(arr, comp);
1919

20-
// This simply copies back if the result isn't in the original array,
21-
// which happens on an odd number of passes.
22-
if (result !== arr) {
23-
pass(result, null, arr.length, arr);
24-
}
20+
// This simply copies back if the result isn't in the original array,
21+
// which happens on an odd number of passes.
22+
if (result !== arr) {
23+
pass(result, null, arr.length, arr);
24+
}
2525

26-
return arr;
27-
};
26+
return arr;
27+
};
28+
29+
// Execute the sort using the input array and a second buffer as work space.
30+
// Returns one of those two, containing the final result.
31+
function exec(arr, comp) {
32+
if (typeof(comp) !== 'function') {
33+
comp = function(a, b) {
34+
return String(a).localeCompare(b);
35+
};
36+
}
2837

29-
// Execute the sort using the input array and a second buffer as work space.
30-
// Returns one of those two, containing the final result.
31-
function exec(arr, comp) {
32-
if (typeof(comp) !== 'function') {
33-
comp = function(a, b) {
34-
return String(a).localeCompare(b);
35-
};
36-
}
38+
// Short-circuit when there's nothing to sort.
39+
var len = arr.length;
40+
if (len <= 1) {
41+
return arr;
42+
}
3743

38-
// Short-circuit when there's nothing to sort.
39-
var len = arr.length;
40-
if (len <= 1) {
41-
return arr;
42-
}
44+
// Rather than dividing input, simply iterate chunks of 1, 2, 4, 8, etc.
45+
// Chunks are the size of the left or right hand in merge sort.
46+
// Stop when the left-hand covers all of the array.
47+
var buffer = new Array(len);
48+
for (var chk = 1; chk < len; chk *= 2) {
49+
pass(arr, comp, chk, buffer);
4350

44-
// Rather than dividing input, simply iterate chunks of 1, 2, 4, 8, etc.
45-
// Chunks are the size of the left or right hand in merge sort.
46-
// Stop when the left-hand covers all of the array.
47-
var buffer = new Array(len);
48-
for (var chk = 1; chk < len; chk *= 2) {
49-
pass(arr, comp, chk, buffer);
51+
var tmp = arr;
52+
arr = buffer;
53+
buffer = tmp;
54+
}
5055

51-
var tmp = arr;
52-
arr = buffer;
53-
buffer = tmp;
56+
return arr;
5457
}
5558

56-
return arr;
57-
}
58-
59-
// Run a single pass with the given chunk size.
60-
var pass = function(arr, comp, chk, result) {
61-
var len = arr.length;
62-
var i = 0;
63-
// Step size / double chunk size.
64-
var dbl = chk * 2;
65-
// Bounds of the left and right chunks.
66-
var l, r, e;
67-
// Iterators over the left and right chunk.
68-
var li, ri;
69-
70-
// Iterate over pairs of chunks.
71-
for (l = 0; l < len; l += dbl) {
72-
r = l + chk;
73-
e = r + chk;
74-
if (r > len) r = len;
75-
if (e > len) e = len;
76-
77-
// Iterate both chunks in parallel.
78-
li = l;
79-
ri = r;
80-
while (true) {
81-
// Compare the chunks.
82-
if (li < r && ri < e) {
83-
// This works for a regular `sort()` compatible comparator,
84-
// but also for a simple comparator like: `a > b`
85-
if (comp(arr[li], arr[ri]) <= 0) {
59+
// Run a single pass with the given chunk size.
60+
var pass = function(arr, comp, chk, result) {
61+
var len = arr.length;
62+
var i = 0;
63+
// Step size / double chunk size.
64+
var dbl = chk * 2;
65+
// Bounds of the left and right chunks.
66+
var l, r, e;
67+
// Iterators over the left and right chunk.
68+
var li, ri;
69+
70+
// Iterate over pairs of chunks.
71+
for (l = 0; l < len; l += dbl) {
72+
r = l + chk;
73+
e = r + chk;
74+
if (r > len) r = len;
75+
if (e > len) e = len;
76+
77+
// Iterate both chunks in parallel.
78+
li = l;
79+
ri = r;
80+
while (true) {
81+
// Compare the chunks.
82+
if (li < r && ri < e) {
83+
// This works for a regular `sort()` compatible comparator,
84+
// but also for a simple comparator like: `a > b`
85+
if (comp(arr[li], arr[ri]) <= 0) {
86+
result[i++] = arr[li++];
87+
}
88+
else {
89+
result[i++] = arr[ri++];
90+
}
91+
}
92+
// Nothing to compare, just flush what's left.
93+
else if (li < r) {
8694
result[i++] = arr[li++];
8795
}
88-
else {
96+
else if (ri < e) {
8997
result[i++] = arr[ri++];
9098
}
91-
}
92-
// Nothing to compare, just flush what's left.
93-
else if (li < r) {
94-
result[i++] = arr[li++];
95-
}
96-
else if (ri < e) {
97-
result[i++] = arr[ri++];
98-
}
99-
// Both iterators are at the chunk ends.
100-
else {
101-
break;
99+
// Both iterators are at the chunk ends.
100+
else {
101+
break;
102+
}
102103
}
103104
}
104-
}
105-
};
105+
};
106106

107-
return stable;
107+
return stable;
108108

109109
})));

stable.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)