ranges-sort 5.0.6 → 5.0.12
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/LICENSE +1 -1
- package/README.md +4 -5
- package/dist/ranges-sort.esm.js +2 -68
- package/dist/ranges-sort.umd.js +2 -2
- package/examples/_quickTake.js +1 -0
- package/package.json +24 -76
- package/types/index.d.ts +10 -7
- package/examples/api.json +0 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010-
|
|
3
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -26,18 +26,17 @@
|
|
|
26
26
|
|
|
27
27
|
## Install
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `4.1.0`.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
npm i ranges-sort
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
If you need a legacy version which works with `require`, use version 4.1.0
|
|
36
|
-
|
|
37
35
|
## Quick Take
|
|
38
36
|
|
|
39
37
|
```js
|
|
40
38
|
import { strict as assert } from "assert";
|
|
39
|
+
|
|
41
40
|
import { rSort } from "ranges-sort";
|
|
42
41
|
|
|
43
42
|
// Ranges (see codsen.com/ranges/) are sorted:
|
|
@@ -57,7 +56,7 @@ assert.deepEqual(
|
|
|
57
56
|
|
|
58
57
|
## Documentation
|
|
59
58
|
|
|
60
|
-
Please [visit codsen.com](https://codsen.com/os/ranges-sort/) for a full description of the API
|
|
59
|
+
Please [visit codsen.com](https://codsen.com/os/ranges-sort/) for a full description of the API.
|
|
61
60
|
|
|
62
61
|
## Contributing
|
|
63
62
|
|
|
@@ -67,6 +66,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
67
66
|
|
|
68
67
|
MIT License
|
|
69
68
|
|
|
70
|
-
Copyright (c) 2010-
|
|
69
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
71
70
|
|
|
72
71
|
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
|
package/dist/ranges-sort.esm.js
CHANGED
|
@@ -1,76 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-sort
|
|
3
3
|
* @fileoverview Sort string index ranges
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.12
|
|
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
|
|
11
|
-
|
|
12
|
-
const version = version$1;
|
|
13
|
-
const defaults = {
|
|
14
|
-
strictlyTwoElementsInRangeArrays: false,
|
|
15
|
-
progressFn: null,
|
|
16
|
-
};
|
|
17
|
-
function rSort(arrOfRanges, originalOptions) {
|
|
18
|
-
if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
|
|
19
|
-
return arrOfRanges;
|
|
20
|
-
}
|
|
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!`);
|
|
36
|
-
}
|
|
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!`);
|
|
50
|
-
}
|
|
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
|
-
}
|
|
72
|
-
return 1;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export { defaults, rSort, version };
|
|
10
|
+
var u="5.0.12";var m=u,d={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function g(r,l){if(!Array.isArray(r)||!r.length)return r;let n={...d,...l},s,o;if(n.strictlyTwoElementsInRangeArrays&&!r.every((e,t)=>!Array.isArray(e)||e.length!==2?(s=t,o=e.length,!1):!0))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(r[s],null,4)}) has not two but ${o} elements!`);if(!r.every((e,t)=>!Array.isArray(e)||!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0?(s=t,!1):!0))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(r[s],null,4)}) does not consist of only natural numbers!`);let a=r.length**2,i=0;return Array.from(r).sort((e,t)=>(n.progressFn&&(i+=1,n.progressFn(Math.floor(i*100/a))),e[0]===t[0]?e[1]<t[1]?-1:e[1]>t[1]?1:0:e[0]<t[0]?-1:1))}export{d as defaults,g as rSort,m as 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.12
|
|
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
|
-
|
|
10
|
+
var rangesSort=(()=>{var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames,p=Object.getOwnPropertySymbols;var d=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var c=(e,r,t)=>r in e?u(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,l=(e,r)=>{for(var t in r||(r={}))d.call(r,t)&&c(e,t,r[t]);if(p)for(var t of p(r))b.call(r,t)&&c(e,t,r[t]);return e};var x=e=>u(e,"__esModule",{value:!0});var w=(e,r)=>{for(var t in r)u(e,t,{get:r[t],enumerable:!0})},v=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of f(r))!d.call(e,o)&&(t||o!=="default")&&u(e,o,{get:()=>r[o],enumerable:!(n=h(r,o))||n.enumerable});return e};var T=(e=>(r,t)=>e&&e.get(r)||(t=v(x({}),r,1),e&&e.set(r,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var R={};w(R,{defaults:()=>m,rSort:()=>E,version:()=>j});var y="5.0.12";var j=y,m={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function E(e,r){if(!Array.isArray(e)||!e.length)return e;let t=l(l({},m),r),n,o;if(t.strictlyTwoElementsInRangeArrays&&!e.every((s,i)=>!Array.isArray(s)||s.length!==2?(n=i,o=s.length,!1):!0))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, ${n}th range (${JSON.stringify(e[n],null,4)}) has not two but ${o} elements!`);if(!e.every((s,i)=>!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||!Number.isInteger(s[1])||s[1]<0?(n=i,!1):!0))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, ${n}th range (${JSON.stringify(e[n],null,4)}) does not consist of only natural numbers!`);let g=e.length**2,a=0;return Array.from(e).sort((s,i)=>(t.progressFn&&(a+=1,t.progressFn(Math.floor(a*100/g))),s[0]===i[0]?s[1]<i[1]?-1:s[1]>i[1]?1:0:s[0]<i[0]?-1:1))}return T(R);})();
|
package/examples/_quickTake.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ranges-sort",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.12",
|
|
4
4
|
"description": "Sort string index ranges",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -28,89 +28,37 @@
|
|
|
28
28
|
},
|
|
29
29
|
"types": "types/index.d.ts",
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"prettier": "
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"test": "npm run test:ci && npm run perf",
|
|
47
|
-
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
48
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
49
|
-
"tsc": "tsc",
|
|
50
|
-
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
31
|
+
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
32
|
+
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
33
|
+
"devtest": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
34
|
+
"dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
|
|
35
|
+
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
36
|
+
"lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
|
|
37
|
+
"letspublish": "yarn publish || :",
|
|
38
|
+
"lint": "eslint . --fix",
|
|
39
|
+
"perf": "node perf/check.js",
|
|
40
|
+
"prepare": "echo 'ready'",
|
|
41
|
+
"prettier": "prettier",
|
|
42
|
+
"prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
|
|
43
|
+
"pretest": "yarn run lect && yarn run build",
|
|
44
|
+
"test": "yarn run devtest",
|
|
45
|
+
"unit": "uvu test"
|
|
51
46
|
},
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
49
|
+
},
|
|
50
|
+
"c8": {
|
|
51
|
+
"check-coverage": true,
|
|
52
|
+
"exclude": [
|
|
53
|
+
"**/test/**/*.*"
|
|
58
54
|
],
|
|
59
|
-
"
|
|
55
|
+
"lines": 100
|
|
60
56
|
},
|
|
61
57
|
"lect": {
|
|
62
58
|
"licence": {
|
|
63
59
|
"extras": [
|
|
64
60
|
""
|
|
65
61
|
]
|
|
66
|
-
},
|
|
67
|
-
"req": "{ rSort }",
|
|
68
|
-
"various": {
|
|
69
|
-
"devDependencies": []
|
|
70
62
|
}
|
|
71
|
-
},
|
|
72
|
-
"dependencies": {
|
|
73
|
-
"@babel/runtime": "^7.16.3"
|
|
74
|
-
},
|
|
75
|
-
"devDependencies": {
|
|
76
|
-
"@babel/cli": "^7.16.0",
|
|
77
|
-
"@babel/core": "^7.16.0",
|
|
78
|
-
"@babel/node": "^7.16.0",
|
|
79
|
-
"@babel/plugin-external-helpers": "^7.16.0",
|
|
80
|
-
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
81
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
82
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
83
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
84
|
-
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
85
|
-
"@babel/preset-env": "^7.16.4",
|
|
86
|
-
"@babel/preset-typescript": "^7.16.0",
|
|
87
|
-
"@babel/register": "^7.16.0",
|
|
88
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
89
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
90
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
91
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
92
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
93
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
94
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
95
|
-
"@types/node": "^16.11.9",
|
|
96
|
-
"@types/tap": "^15.0.5",
|
|
97
|
-
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
98
|
-
"@typescript-eslint/parser": "^5.4.0",
|
|
99
|
-
"core-js": "^3.19.1",
|
|
100
|
-
"cross-env": "^7.0.3",
|
|
101
|
-
"eslint": "^8.3.0",
|
|
102
|
-
"lect": "^0.18.6",
|
|
103
|
-
"rollup": "^2.60.0",
|
|
104
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
105
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
106
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
107
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
108
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
109
|
-
"tap": "^15.1.2",
|
|
110
|
-
"tslib": "^2.3.1",
|
|
111
|
-
"typescript": "^4.5.2"
|
|
112
|
-
},
|
|
113
|
-
"engines": {
|
|
114
|
-
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
115
63
|
}
|
|
116
64
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
declare type Range =
|
|
1
|
+
declare type Range =
|
|
2
|
+
| [from: number, to: number]
|
|
3
|
+
| [from: number, to: number, whatToInsert: string | null | undefined];
|
|
2
4
|
declare type Ranges = Range[] | null;
|
|
3
|
-
|
|
4
5
|
declare const version: string;
|
|
5
|
-
|
|
6
6
|
declare type ProgressFn = (percentageDone: number) => void;
|
|
7
7
|
interface Opts {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
strictlyTwoElementsInRangeArrays: boolean;
|
|
9
|
+
progressFn: undefined | null | ProgressFn;
|
|
10
10
|
}
|
|
11
11
|
declare const defaults: Opts;
|
|
12
|
-
declare function rSort(
|
|
12
|
+
declare function rSort(
|
|
13
|
+
arrOfRanges: Ranges,
|
|
14
|
+
originalOptions?: Partial<Opts>
|
|
15
|
+
): Ranges;
|
|
13
16
|
|
|
14
|
-
export { defaults, rSort, version };
|
|
17
|
+
export { Range, Ranges, defaults, rSort, version };
|
package/examples/api.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { rSort } from \"ranges-sort\";\n\n// Ranges (see codsen.com/ranges/) are sorted:\nassert.deepEqual(\n rSort([\n [2, 3],\n [9, 10, \"bad grey wolf\"],\n [1, 2],\n ]),\n [\n [1, 2],\n [2, 3],\n [9, 10, \"bad grey wolf\"],\n ]\n);"}}
|