ranges-sort 5.0.4 → 5.0.10
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/CHANGELOG.md +0 -20
- package/LICENSE +1 -1
- package/README.md +4 -1
- package/dist/ranges-sort.esm.js +2 -60
- package/dist/ranges-sort.umd.js +2 -2
- package/examples/_quickTake.js +1 -0
- package/package.json +21 -80
- package/types/index.d.ts +1 -3
- package/examples/api.json +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,26 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## 5.0.3 (2021-11-02)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
|
|
11
|
-
|
|
12
|
-
### Features
|
|
13
|
-
|
|
14
|
-
- migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
|
|
15
|
-
|
|
16
|
-
### BREAKING CHANGES
|
|
17
|
-
|
|
18
|
-
- programs now are in ES Modules and won't work with Common JS require()
|
|
19
|
-
|
|
20
|
-
## 5.0.1 (2021-09-13)
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
25
|
-
|
|
26
6
|
## 5.0.0 (2021-09-09)
|
|
27
7
|
|
|
28
8
|
### Features
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010
|
|
3
|
+
Copyright (c) 2010-2021 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
|
@@ -38,6 +38,7 @@ If you need a legacy version which works with `require`, use version 4.1.0
|
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
40
|
import { strict as assert } from "assert";
|
|
41
|
+
|
|
41
42
|
import { rSort } from "ranges-sort";
|
|
42
43
|
|
|
43
44
|
// Ranges (see codsen.com/ranges/) are sorted:
|
|
@@ -57,7 +58,7 @@ assert.deepEqual(
|
|
|
57
58
|
|
|
58
59
|
## Documentation
|
|
59
60
|
|
|
60
|
-
Please [visit codsen.com](https://codsen.com/os/ranges-sort/) for a full description of the API
|
|
61
|
+
Please [visit codsen.com](https://codsen.com/os/ranges-sort/) for a full description of the API.
|
|
61
62
|
|
|
62
63
|
## Contributing
|
|
63
64
|
|
|
@@ -69,4 +70,6 @@ MIT License
|
|
|
69
70
|
|
|
70
71
|
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
71
72
|
|
|
73
|
+
|
|
72
74
|
<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">
|
|
75
|
+
|
package/dist/ranges-sort.esm.js
CHANGED
|
@@ -1,68 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-sort
|
|
3
3
|
* @fileoverview Sort string index ranges
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.10
|
|
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,
|
|
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;
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
})) {
|
|
34
|
-
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!`);
|
|
35
|
-
}
|
|
36
|
-
if (!arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
37
|
-
if (!Number.isInteger(rangeArr[0]) || rangeArr[0] < 0 || !Number.isInteger(rangeArr[1]) || rangeArr[1] < 0) {
|
|
38
|
-
culpritsIndex = indx;
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
})) {
|
|
43
|
-
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!`);
|
|
44
|
-
}
|
|
45
|
-
const maxPossibleIterations = arrOfRanges.filter(range => range).length ** 2;
|
|
46
|
-
let counter = 0;
|
|
47
|
-
return Array.from(arrOfRanges).filter(range => range).sort((range1, range2) => {
|
|
48
|
-
if (opts.progressFn) {
|
|
49
|
-
counter += 1;
|
|
50
|
-
opts.progressFn(Math.floor(counter * 100 / maxPossibleIterations));
|
|
51
|
-
}
|
|
52
|
-
if (range1[0] === range2[0]) {
|
|
53
|
-
if (range1[1] < range2[1]) {
|
|
54
|
-
return -1;
|
|
55
|
-
}
|
|
56
|
-
if (range1[1] > range2[1]) {
|
|
57
|
-
return 1;
|
|
58
|
-
}
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
|
61
|
-
if (range1[0] < range2[0]) {
|
|
62
|
-
return -1;
|
|
63
|
-
}
|
|
64
|
-
return 1;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export { defaults, rSort, version };
|
|
10
|
+
var u="5.0.10";var m=u,c={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function g(r,l){if(!Array.isArray(r)||!r.length)return r;let n={...c,...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{c 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.10
|
|
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 c=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var d=(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={}))c.call(r,t)&&d(e,t,r[t]);if(p)for(var t of p(r))b.call(r,t)&&d(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))!c.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 F={};w(F,{defaults:()=>m,rSort:()=>E,version:()=>j});var y="5.0.10";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(F);})();
|
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.10",
|
|
4
4
|
"description": "Sort string index ranges",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -28,93 +28,34 @@
|
|
|
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
|
-
"
|
|
43
|
-
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
44
|
-
"republish": "npm publish || :",
|
|
45
|
-
"tap": "tap",
|
|
46
|
-
"pretest": "npm run build",
|
|
47
|
-
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
48
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
49
|
-
"tsc": "tsc",
|
|
50
|
-
"unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
|
|
31
|
+
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
32
|
+
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
33
|
+
"dts": "rollup -c",
|
|
34
|
+
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
35
|
+
"lect": "node '../../ops/lect/lect.js'",
|
|
36
|
+
"letspublish": "yarn publish || :",
|
|
37
|
+
"lint": "eslint . --fix",
|
|
38
|
+
"perf": "node perf/check.js",
|
|
39
|
+
"prepare": "echo 'ready'",
|
|
40
|
+
"pretest": "yarn run lect && yarn run build",
|
|
41
|
+
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
42
|
+
"unit": "uvu test"
|
|
51
43
|
},
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"--no-warnings",
|
|
60
|
-
"--experimental-loader",
|
|
61
|
-
"@istanbuljs/esm-loader-hook"
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
46
|
+
},
|
|
47
|
+
"c8": {
|
|
48
|
+
"check-coverage": true,
|
|
49
|
+
"exclude": [
|
|
50
|
+
"**/test/**/*.*"
|
|
62
51
|
],
|
|
63
|
-
"
|
|
52
|
+
"lines": 100
|
|
64
53
|
},
|
|
65
54
|
"lect": {
|
|
66
55
|
"licence": {
|
|
67
56
|
"extras": [
|
|
68
57
|
""
|
|
69
58
|
]
|
|
70
|
-
},
|
|
71
|
-
"req": "{ rSort }",
|
|
72
|
-
"various": {
|
|
73
|
-
"devDependencies": []
|
|
74
59
|
}
|
|
75
|
-
},
|
|
76
|
-
"dependencies": {
|
|
77
|
-
"@babel/runtime": "^7.16.0"
|
|
78
|
-
},
|
|
79
|
-
"devDependencies": {
|
|
80
|
-
"@babel/cli": "^7.16.0",
|
|
81
|
-
"@babel/core": "^7.16.0",
|
|
82
|
-
"@babel/node": "^7.16.0",
|
|
83
|
-
"@babel/plugin-external-helpers": "^7.16.0",
|
|
84
|
-
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
85
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
86
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
87
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
88
|
-
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
89
|
-
"@babel/preset-env": "^7.16.0",
|
|
90
|
-
"@babel/preset-typescript": "^7.16.0",
|
|
91
|
-
"@babel/register": "^7.16.0",
|
|
92
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
93
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
94
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
95
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
96
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
97
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
98
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
99
|
-
"@types/node": "^16.11.6",
|
|
100
|
-
"@types/tap": "^15.0.5",
|
|
101
|
-
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
|
102
|
-
"@typescript-eslint/parser": "^5.3.0",
|
|
103
|
-
"core-js": "^3.19.1",
|
|
104
|
-
"cross-env": "^7.0.3",
|
|
105
|
-
"eslint": "^8.1.0",
|
|
106
|
-
"lect": "^0.18.4",
|
|
107
|
-
"rollup": "^2.59.0",
|
|
108
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
109
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
110
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
111
|
-
"rollup-plugin-dts": "^4.0.0",
|
|
112
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
113
|
-
"tap": "^15.0.10",
|
|
114
|
-
"tslib": "^2.3.1",
|
|
115
|
-
"typescript": "^4.4.4"
|
|
116
|
-
},
|
|
117
|
-
"engines": {
|
|
118
|
-
"node": ">=12"
|
|
119
60
|
}
|
|
120
61
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
|
|
2
2
|
declare type Ranges = Range[] | null;
|
|
3
|
-
|
|
4
3
|
declare const version: string;
|
|
5
|
-
|
|
6
4
|
declare type ProgressFn = (percentageDone: number) => void;
|
|
7
5
|
interface Opts {
|
|
8
6
|
strictlyTwoElementsInRangeArrays: boolean;
|
|
@@ -11,4 +9,4 @@ interface Opts {
|
|
|
11
9
|
declare const defaults: Opts;
|
|
12
10
|
declare function rSort(arrOfRanges: Ranges, originalOptions?: Partial<Opts>): Ranges;
|
|
13
11
|
|
|
14
|
-
export { defaults, rSort, version };
|
|
12
|
+
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);"}}
|