ranges-sort 5.0.5 → 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ranges-sort.esm.js +56 -48
- package/dist/ranges-sort.umd.js +2 -2
- package/package.json +19 -23
package/dist/ranges-sort.esm.js
CHANGED
|
@@ -1,68 +1,76 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-sort
|
|
3
3
|
* @fileoverview Sort string index ranges
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.6
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ranges-sort/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var version$1 = "5.0.
|
|
10
|
+
var version$1 = "5.0.6";
|
|
11
11
|
|
|
12
12
|
const version = version$1;
|
|
13
13
|
const defaults = {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
strictlyTwoElementsInRangeArrays: false,
|
|
15
|
+
progressFn: null,
|
|
16
16
|
};
|
|
17
17
|
function rSort(arrOfRanges, originalOptions) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const opts = { ...defaults,
|
|
22
|
-
...originalOptions
|
|
23
|
-
};
|
|
24
|
-
let culpritsIndex;
|
|
25
|
-
let culpritsLen;
|
|
26
|
-
if (opts.strictlyTwoElementsInRangeArrays && !arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
27
|
-
if (rangeArr.length !== 2) {
|
|
28
|
-
culpritsIndex = indx;
|
|
29
|
-
culpritsLen = rangeArr.length;
|
|
30
|
-
return false;
|
|
18
|
+
if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
|
|
19
|
+
return arrOfRanges;
|
|
31
20
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
const opts = { ...defaults, ...originalOptions };
|
|
22
|
+
let culpritsIndex;
|
|
23
|
+
let culpritsLen;
|
|
24
|
+
if (opts.strictlyTwoElementsInRangeArrays &&
|
|
25
|
+
!arrOfRanges
|
|
26
|
+
.filter((range) => range)
|
|
27
|
+
.every((rangeArr, indx) => {
|
|
28
|
+
if (rangeArr.length !== 2) {
|
|
29
|
+
culpritsIndex = indx;
|
|
30
|
+
culpritsLen = rangeArr.length;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
})) {
|
|
35
|
+
throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 4)}) has not two but ${culpritsLen} elements!`);
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
if (!arrOfRanges
|
|
38
|
+
.filter((range) => range)
|
|
39
|
+
.every((rangeArr, indx) => {
|
|
40
|
+
if (!Number.isInteger(rangeArr[0]) ||
|
|
41
|
+
rangeArr[0] < 0 ||
|
|
42
|
+
!Number.isInteger(rangeArr[1]) ||
|
|
43
|
+
rangeArr[1] < 0) {
|
|
44
|
+
culpritsIndex = indx;
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
})) {
|
|
49
|
+
throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 4)}) does not consist of only natural numbers!`);
|
|
51
50
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const maxPossibleIterations = arrOfRanges.filter((range) => range).length ** 2;
|
|
52
|
+
let counter = 0;
|
|
53
|
+
return Array.from(arrOfRanges)
|
|
54
|
+
.filter((range) => range)
|
|
55
|
+
.sort((range1, range2) => {
|
|
56
|
+
if (opts.progressFn) {
|
|
57
|
+
counter += 1;
|
|
58
|
+
opts.progressFn(Math.floor((counter * 100) / maxPossibleIterations));
|
|
59
|
+
}
|
|
60
|
+
if (range1[0] === range2[0]) {
|
|
61
|
+
if (range1[1] < range2[1]) {
|
|
62
|
+
return -1;
|
|
63
|
+
}
|
|
64
|
+
if (range1[1] > range2[1]) {
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
if (range1[0] < range2[0]) {
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
57
72
|
return 1;
|
|
58
|
-
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
|
61
|
-
if (range1[0] < range2[0]) {
|
|
62
|
-
return -1;
|
|
63
|
-
}
|
|
64
|
-
return 1;
|
|
65
|
-
});
|
|
73
|
+
});
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
export { defaults, rSort, version };
|
package/dist/ranges-sort.umd.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-sort
|
|
3
3
|
* @fileoverview Sort string index ranges
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.6
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ranges-sort/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).rangesSort={})}(this,(function(e){"use strict";const r={strictlyTwoElementsInRangeArrays:!1,progressFn:null};e.defaults=r,e.rSort=function(e,n){if(!Array.isArray(e)||!e.length)return e;const t={...r,...n};let s,o;if(t.strictlyTwoElementsInRangeArrays&&!e.filter((e=>e)).every(((e,r)=>2===e.length||(s=r,o=e.length,!1))))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${s}th range (${JSON.stringify(e[s],null,4)}) has not two but ${o} elements!`);if(!e.filter((e=>e)).every(((e,r)=>!(!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0)||(s=r,!1))))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${s}th range (${JSON.stringify(e[s],null,4)}) does not consist of only natural numbers!`);const i=e.filter((e=>e)).length**2;let a=0;return Array.from(e).filter((e=>e)).sort(((e,r)=>(t.progressFn&&(a+=1,t.progressFn(Math.floor(100*a/i))),e[0]===r[0]?e[1]<r[1]?-1:e[1]>r[1]?1:0:e[0]<r[0]?-1:1)))},e.version="5.0.
|
|
10
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).rangesSort={})}(this,(function(e){"use strict";const r={strictlyTwoElementsInRangeArrays:!1,progressFn:null};e.defaults=r,e.rSort=function(e,n){if(!Array.isArray(e)||!e.length)return e;const t={...r,...n};let s,o;if(t.strictlyTwoElementsInRangeArrays&&!e.filter((e=>e)).every(((e,r)=>2===e.length||(s=r,o=e.length,!1))))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${s}th range (${JSON.stringify(e[s],null,4)}) has not two but ${o} elements!`);if(!e.filter((e=>e)).every(((e,r)=>!(!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0)||(s=r,!1))))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${s}th range (${JSON.stringify(e[s],null,4)}) does not consist of only natural numbers!`);const i=e.filter((e=>e)).length**2;let a=0;return Array.from(e).filter((e=>e)).sort(((e,r)=>(t.progressFn&&(a+=1,t.progressFn(Math.floor(100*a/i))),e[0]===r[0]?e[1]<r[1]?-1:e[1]>r[1]?1:0:e[0]<r[0]?-1:1)))},e.version="5.0.6",Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ranges-sort",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.6",
|
|
4
4
|
"description": "Sort string index ranges",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -29,13 +29,12 @@
|
|
|
29
29
|
"types": "types/index.d.ts",
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "rollup -c",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"build:esbuild": "node '../../scripts/esbuild.js'",
|
|
33
|
+
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
34
|
+
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
|
|
34
35
|
"clean_types": "../../scripts/cleanTypes.js",
|
|
35
36
|
"dev": "rollup -c --dev",
|
|
36
37
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
37
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
38
|
-
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
39
38
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
40
39
|
"lect": "lect",
|
|
41
40
|
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
|
|
@@ -44,17 +43,14 @@
|
|
|
44
43
|
"republish": "npm publish || :",
|
|
45
44
|
"tap": "tap",
|
|
46
45
|
"pretest": "npm run build",
|
|
47
|
-
"test": "npm run
|
|
46
|
+
"test": "npm run test:ci && npm run perf",
|
|
47
|
+
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
48
48
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
49
49
|
"tsc": "tsc",
|
|
50
|
-
"unittest": "tap --no-only --
|
|
50
|
+
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
51
51
|
},
|
|
52
52
|
"tap": {
|
|
53
53
|
"check-coverage": false,
|
|
54
|
-
"coverage-report": [
|
|
55
|
-
"json-summary",
|
|
56
|
-
"text"
|
|
57
|
-
],
|
|
58
54
|
"node-arg": [
|
|
59
55
|
"--no-warnings",
|
|
60
56
|
"--experimental-loader",
|
|
@@ -74,7 +70,7 @@
|
|
|
74
70
|
}
|
|
75
71
|
},
|
|
76
72
|
"dependencies": {
|
|
77
|
-
"@babel/runtime": "^7.16.
|
|
73
|
+
"@babel/runtime": "^7.16.3"
|
|
78
74
|
},
|
|
79
75
|
"devDependencies": {
|
|
80
76
|
"@babel/cli": "^7.16.0",
|
|
@@ -85,8 +81,8 @@
|
|
|
85
81
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
86
82
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
87
83
|
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
88
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
89
|
-
"@babel/preset-env": "^7.16.
|
|
84
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
85
|
+
"@babel/preset-env": "^7.16.4",
|
|
90
86
|
"@babel/preset-typescript": "^7.16.0",
|
|
91
87
|
"@babel/register": "^7.16.0",
|
|
92
88
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
@@ -96,25 +92,25 @@
|
|
|
96
92
|
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
97
93
|
"@rollup/plugin-strip": "^2.1.0",
|
|
98
94
|
"@rollup/plugin-typescript": "^8.3.0",
|
|
99
|
-
"@types/node": "^16.11.
|
|
95
|
+
"@types/node": "^16.11.9",
|
|
100
96
|
"@types/tap": "^15.0.5",
|
|
101
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
102
|
-
"@typescript-eslint/parser": "^5.
|
|
97
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
98
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
103
99
|
"core-js": "^3.19.1",
|
|
104
100
|
"cross-env": "^7.0.3",
|
|
105
|
-
"eslint": "^8.
|
|
106
|
-
"lect": "^0.18.
|
|
107
|
-
"rollup": "^2.
|
|
101
|
+
"eslint": "^8.3.0",
|
|
102
|
+
"lect": "^0.18.6",
|
|
103
|
+
"rollup": "^2.60.0",
|
|
108
104
|
"rollup-plugin-ascii": "^0.0.3",
|
|
109
105
|
"rollup-plugin-banner": "^0.2.1",
|
|
110
106
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
111
107
|
"rollup-plugin-dts": "^4.0.1",
|
|
112
108
|
"rollup-plugin-terser": "^7.0.2",
|
|
113
|
-
"tap": "^15.
|
|
109
|
+
"tap": "^15.1.2",
|
|
114
110
|
"tslib": "^2.3.1",
|
|
115
|
-
"typescript": "^4.
|
|
111
|
+
"typescript": "^4.5.2"
|
|
116
112
|
},
|
|
117
113
|
"engines": {
|
|
118
|
-
"node": ">=
|
|
114
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
119
115
|
}
|
|
120
116
|
}
|