ranges-process-outside 4.0.16 → 5.0.2
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
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
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.1 (2021-09-13)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
11
|
+
|
|
12
|
+
## 5.0.0 (2021-09-09)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- migrate to ES Modules ([8c9d95d](https://github.com/codsen/codsen/commit/8c9d95d5dea0b769c2f070397141918a4893d575))
|
|
17
|
+
|
|
18
|
+
### BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
- programs now are in ES Modules and won't work with Common JS require()
|
|
21
|
+
|
|
22
|
+
## 4.1.0 (2021-05-24)
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
- config file based major bump blacklisting ([e15f9bb](https://github.com/codsen/codsen/commit/e15f9bba1c4fd5f847ac28b3f38fa6ee633f5dca))
|
|
27
|
+
|
|
6
28
|
## 4.0.15 (2021-04-11)
|
|
7
29
|
|
|
8
30
|
### Reverts
|
package/README.md
CHANGED
|
@@ -26,10 +26,14 @@
|
|
|
26
26
|
|
|
27
27
|
## Install
|
|
28
28
|
|
|
29
|
+
This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:
|
|
30
|
+
|
|
29
31
|
```bash
|
|
30
32
|
npm i ranges-process-outside
|
|
31
33
|
```
|
|
32
34
|
|
|
35
|
+
If you need a legacy version which works with `require`, use version 4.1.0
|
|
36
|
+
|
|
33
37
|
## Quick Take
|
|
34
38
|
|
|
35
39
|
```js
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-process-outside
|
|
3
3
|
* @fileoverview Iterate string considering ranges, as if they were already applied
|
|
4
|
-
* @version
|
|
4
|
+
* @version 5.0.2
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ranges-process-outside/}
|
|
@@ -11,7 +11,7 @@ import runes from 'runes';
|
|
|
11
11
|
import { rInvert } from 'ranges-invert';
|
|
12
12
|
import { rCrop } from 'ranges-crop';
|
|
13
13
|
|
|
14
|
-
var version$1 = "
|
|
14
|
+
var version$1 = "5.0.2";
|
|
15
15
|
|
|
16
16
|
const version = version$1;
|
|
17
17
|
function rProcessOutside(originalStr, originalRanges, cb, skipChecks = false) {
|
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-process-outside
|
|
3
3
|
* @fileoverview Iterate string considering ranges, as if they were already applied
|
|
4
|
-
* @version
|
|
4
|
+
* @version 5.0.2
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ranges-process-outside/}
|
|
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).rangesProcessOutside={})}(this,(function(e){"use strict";
|
|
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).rangesProcessOutside={})}(this,(function(e){"use strict";var r={exports:{}};const n=55296,t=127995,s=127999,o=[776,2359,2359,2367,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520];function i(e){if("string"!=typeof e)throw new Error("string cannot be undefined or null");const r=[];let n=0,t=0;for(;n<e.length;)t+=a(n+t,e),f(e[n+t])&&t++,l(e[n+t])&&t++,g(e[n+t])&&t++,y(e[n+t])?t++:(r.push(e.substring(n,n+t)),n+=t,t=0);return r}function a(e,r){const o=r[e];if(!function(e){return e&&p(e[0].charCodeAt(0),n,56319)}(o)||e===r.length-1)return 1;const i=o+r[e+1];let a=r.substring(e+2,e+5);return u(i)&&u(a)||function(e){return p(h(e),t,s)}(a)?4:2}function u(e){return p(h(e),127462,127487)}function l(e){return"string"==typeof e&&p(e.charCodeAt(0),65024,65039)}function g(e){return"string"==typeof e&&p(e.charCodeAt(0),8400,8447)}function f(e){return"string"==typeof e&&-1!==o.indexOf(e.charCodeAt(0))}function y(e){return"string"==typeof e&&8205===e.charCodeAt(0)}function h(e){return(e.charCodeAt(0)-n<<10)+(e.charCodeAt(1)-56320)+65536}function p(e,r,n){return e>=r&&e<=n}r.exports=i,r.exports.substr=function(e,r,n){const t=i(e);if(void 0===r)return e;if(r>=t.length)return"";const s=t.length-r;let o=r+(void 0===n?s:n);return o>r+s&&(o=void 0),t.slice(r,o).join("")};var c=r.exports;
|
|
11
11
|
/**
|
|
12
12
|
* @name ranges-sort
|
|
13
13
|
* @fileoverview Sort string index ranges
|
|
14
|
-
* @version
|
|
14
|
+
* @version 5.0.2
|
|
15
15
|
* @author Roy Revelt, Codsen Ltd
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/ranges-sort/}
|
|
18
|
-
*/
|
|
19
|
-
const c={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function m(e,r){if(!Array.isArray(e)||!e.length)return e;const n={...c,...r};let t,s;if(n.strictlyTwoElementsInRangeArrays&&!e.filter((e=>e)).every(((e,r)=>2===e.length||(t=r,s=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, ${t}th range (${JSON.stringify(e[t],null,4)}) has not two but ${s} elements!`);if(!e.filter((e=>e)).every(((e,r)=>!(!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0)||(t=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, ${t}th range (${JSON.stringify(e[t],null,4)}) does not consist of only natural numbers!`);const o=e.filter((e=>e)).length**2;let i=0;return Array.from(e).filter((e=>e)).sort(((e,r)=>(n.progressFn&&(i+=1,n.progressFn(Math.floor(100*i/o))),e[0]===r[0]?e[1]<r[1]?-1:e[1]>r[1]?1:0:e[0]<r[0]?-1:1)))}
|
|
18
|
+
*/const m={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function T(e,r){if(!Array.isArray(e)||!e.length)return e;const n={...m,...r};let t,s;if(n.strictlyTwoElementsInRangeArrays&&!e.filter((e=>e)).every(((e,r)=>2===e.length||(t=r,s=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, ${t}th range (${JSON.stringify(e[t],null,4)}) has not two but ${s} elements!`);if(!e.filter((e=>e)).every(((e,r)=>!(!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0)||(t=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, ${t}th range (${JSON.stringify(e[t],null,4)}) does not consist of only natural numbers!`);const o=e.filter((e=>e)).length**2;let i=0;return Array.from(e).filter((e=>e)).sort(((e,r)=>(n.progressFn&&(i+=1,n.progressFn(Math.floor(100*i/o))),e[0]===r[0]?e[1]<r[1]?-1:e[1]>r[1]?1:0:e[0]<r[0]?-1:1)))}
|
|
20
19
|
/**
|
|
21
20
|
* @name ranges-merge
|
|
22
21
|
* @fileoverview Merge and sort string index ranges
|
|
23
|
-
* @version
|
|
22
|
+
* @version 8.0.2
|
|
24
23
|
* @author Roy Revelt, Codsen Ltd
|
|
25
24
|
* @license MIT
|
|
26
25
|
* {@link https://codsen.com/os/ranges-merge/}
|
|
27
|
-
*/const
|
|
26
|
+
*/const d={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function w(e,r){function n(e){return e&&"object"==typeof e&&!Array.isArray(e)}if(!Array.isArray(e)||!e.length)return null;let t;if(r){if(!n(r))throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n${JSON.stringify(r,null,4)} (type ${typeof r})`);if(t={...d,...r},t.progressFn&&n(t.progressFn)&&!Object.keys(t.progressFn).length)t.progressFn=null;else if(t.progressFn&&"function"!=typeof t.progressFn)throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof t.progressFn}", equal to ${JSON.stringify(t.progressFn,null,4)}`);if(t.mergeType&&1!=+t.mergeType&&2!=+t.mergeType)throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof t.mergeType}", equal to ${JSON.stringify(t.mergeType,null,4)}`);if("boolean"!=typeof t.joinRangesThatTouchEdges)throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof t.joinRangesThatTouchEdges}", equal to ${JSON.stringify(t.joinRangesThatTouchEdges,null,4)}`)}else t={...d};const s=e.filter((e=>e)).map((e=>[...e])).filter((e=>void 0!==e[2]||e[0]!==e[1]));let o,i,a;if(o=t.progressFn?T(s,{progressFn:e=>{a=Math.floor(e/5),a!==i&&(i=a,t.progressFn(a))}}):T(s),!o)return null;const u=o.length-1;for(let e=u;e>0;e--)t.progressFn&&(a=Math.floor(78*(1-e/u))+21,a!==i&&a>i&&(i=a,t.progressFn(a))),(o[e][0]<=o[e-1][0]||!t.joinRangesThatTouchEdges&&o[e][0]<o[e-1][1]||t.joinRangesThatTouchEdges&&o[e][0]<=o[e-1][1])&&(o[e-1][0]=Math.min(o[e][0],o[e-1][0]),o[e-1][1]=Math.max(o[e][1],o[e-1][1]),void 0!==o[e][2]&&(o[e-1][0]>=o[e][0]||o[e-1][1]<=o[e][1])&&null!==o[e-1][2]&&(null===o[e][2]&&null!==o[e-1][2]?o[e-1][2]=null:null!=o[e-1][2]?2==+t.mergeType&&o[e-1][0]===o[e][0]?o[e-1][2]=o[e][2]:o[e-1][2]+=o[e][2]:o[e-1][2]=o[e][2]),o.splice(e,1),e=o.length);return o.length?o:null}
|
|
28
27
|
/**
|
|
29
28
|
* @name ranges-crop
|
|
30
29
|
* @fileoverview Crop array of ranges when they go beyond the reference string's length
|
|
31
|
-
* @version
|
|
30
|
+
* @version 5.0.2
|
|
32
31
|
* @author Roy Revelt, Codsen Ltd
|
|
33
32
|
* @license MIT
|
|
34
33
|
* {@link https://codsen.com/os/ranges-crop/}
|
|
35
|
-
*/function
|
|
34
|
+
*/function b(e,r){if(null===e)return null;if(!Array.isArray(e))throw new TypeError(`ranges-crop: [THROW_ID_01] The first input's argument must be an array, consisting of range arrays! Currently its type is: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(!Number.isInteger(r))throw new TypeError(`ranges-crop: [THROW_ID_02] The second input's argument must be a natural number or zero (coming from String.length)! Currently its type is: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(!e.filter((e=>e)).length)return e.filter((e=>e));let n=0;if(!e.filter((e=>e)).every(((e,r)=>!(!Number.isInteger(e[0])||!Number.isInteger(e[1]))||(n=r,!1)))){if(Array.isArray(e)&&"number"==typeof e[0]&&"number"==typeof e[1])throw new TypeError(`ranges-crop: [THROW_ID_03] The first argument should be AN ARRAY OF RANGES, not a single range! Currently arrOfRanges = ${JSON.stringify(e,null,0)}!`);throw new TypeError(`ranges-crop: [THROW_ID_04] The first argument should be AN ARRAY OF ARRAYS! Each sub-array means string slice indexes. In our case, here ${n}th range (${JSON.stringify(e[n],null,0)}) does not consist of only natural numbers!`)}if(!e.filter((e=>e)).every(((e,r)=>null==e[2]||"string"==typeof e[2]||(n=r,!1))))throw new TypeError(`ranges-crop: [THROW_ID_05] The third argument, if present at all, should be of a string-type or null. Currently the ${n}th range ${JSON.stringify(e[n],null,0)} has a argument in the range of a type ${typeof e[n][2]}`);const t=(w(e)||[]).filter((e=>e[0]<=r&&(null!=e[2]||e[0]<r))).map((e=>e[1]>r?null!=e[2]?[e[0],r,e[2]]:[e[0],r]:e));return t===[]?null:t}
|
|
36
35
|
/**
|
|
37
36
|
* @name ranges-invert
|
|
38
37
|
* @fileoverview Invert string index ranges
|
|
39
|
-
* @version
|
|
38
|
+
* @version 5.0.2
|
|
40
39
|
* @author Roy Revelt, Codsen Ltd
|
|
41
40
|
* @license MIT
|
|
42
41
|
* {@link https://codsen.com/os/ranges-invert/}
|
|
43
|
-
*/e.rProcessOutside=function(e,r,n,t=!1){if("string"!=typeof e)throw void 0===e?new Error("ranges-process-outside: [THROW_ID_01] the first input argument must be string! It's missing currently (undefined)!"):new Error(`ranges-process-outside: [THROW_ID_02] the first input argument must be string! It was given as:\n${JSON.stringify(e,null,4)} (type ${typeof e})`);if(r&&(!Array.isArray(r)||r.length&&!Array.isArray(r[0])))throw new Error(`ranges-process-outside: [THROW_ID_03] the second input argument must be array of ranges or null! It was given as:\n${JSON.stringify(r,null,4)} (type ${typeof r})`);if("function"!=typeof n)throw new Error(`ranges-process-outside: [THROW_ID_04] the third input argument must be a function! It was given as:\n${JSON.stringify(n,null,4)} (type ${typeof n})`);function s(e,r){(r||[]).forEach((([r,t])=>{for(let s=r;s<t;s++){const r=
|
|
42
|
+
*/e.rProcessOutside=function(e,r,n,t=!1){if("string"!=typeof e)throw void 0===e?new Error("ranges-process-outside: [THROW_ID_01] the first input argument must be string! It's missing currently (undefined)!"):new Error(`ranges-process-outside: [THROW_ID_02] the first input argument must be string! It was given as:\n${JSON.stringify(e,null,4)} (type ${typeof e})`);if(r&&(!Array.isArray(r)||r.length&&!Array.isArray(r[0])))throw new Error(`ranges-process-outside: [THROW_ID_03] the second input argument must be array of ranges or null! It was given as:\n${JSON.stringify(r,null,4)} (type ${typeof r})`);if("function"!=typeof n)throw new Error(`ranges-process-outside: [THROW_ID_04] the third input argument must be a function! It was given as:\n${JSON.stringify(n,null,4)} (type ${typeof n})`);function s(e,r){(r||[]).forEach((([r,t])=>{for(let s=r;s<t;s++){const r=c(e.slice(s))[0].length;n(s,s+r,(e=>{null!=e&&(s+=e)})),r&&r>1&&(s+=r-1)}}))}if(r&&r.length){s(e,b(function(e,r,n){if(!Array.isArray(e)&&null!==e)throw new TypeError(`ranges-invert: [THROW_ID_01] Input's first argument must be an array, consisting of range arrays! Currently its type is: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(!Number.isInteger(r)||r<0)throw new TypeError(`ranges-invert: [THROW_ID_02] Input's second argument must be a natural number or zero (coming from String.length)! Currently its type is: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(Array.isArray(e)&&"number"==typeof e[0]&&"number"==typeof e[1])throw new TypeError(`ranges-invert: [THROW_ID_07] The first argument should be AN ARRAY OF RANGES, not a single range! Currently arrOfRanges = ${JSON.stringify(e,null,0)}!`);if(!Array.isArray(e)||!e.filter((e=>Array.isArray(e)&&e[0]!==e[1])).length||!r)return r?[[0,r]]:null;const t={strictlyTwoElementsInRangeArrays:!1,skipChecks:!1,...n};let s,o,i=0;if(!t.skipChecks&&t.strictlyTwoElementsInRangeArrays&&!e.filter((e=>e)).every(((e,r)=>2===e.length||(i=r,s=e.length,!1))))throw new TypeError(`ranges-invert: [THROW_ID_04] Because opts.strictlyTwoElementsInRangeArrays was enabled, all ranges must be strictly two-element-long. However, the ${i}th range (${JSON.stringify(e[i],null,0)}) has not two but ${s} elements!`);if(!t.skipChecks&&!e.every(((e,r)=>!(!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0)||(i=r,!1))))throw new TypeError(`ranges-invert: [THROW_ID_05] The first argument should be AN ARRAY OF ARRAYS! Each sub-array means string slice indexes. In our case, here ${i+1}th range (${JSON.stringify(e[i],null,0)}) does not consist of only natural numbers!`);return o=t.skipChecks?e.filter((e=>e[0]!==e[1])):w(e.filter((e=>e[0]!==e[1]))),b(o.reduce(((e,n,s,o)=>{const i=[];0===s&&0!==o[0][0]&&i.push([0,o[0][0]]);const a=s<o.length-1?o[s+1][0]:r;if(n[1]!==a){if(t.skipChecks&&n[1]>a)throw new TypeError(`ranges-invert: [THROW_ID_08] The checking (opts.skipChecks) is off and input ranges were not sorted! We nearly wrote range [${n[1]}, ${a}] which is backwards. For investigation, whole ranges array is:\n${JSON.stringify(o,null,0)}`);i.push([n[1],a])}return e.concat(i)}),[]),r)}(r,e.length,{skipChecks:!!t}),e.length))}else s(e,[[0,e.length]])},e.version="5.0.2",Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ranges-process-outside",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Iterate string considering ranges, as if they were already applied",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -21,9 +21,11 @@
|
|
|
21
21
|
"email": "roy@codsen.com",
|
|
22
22
|
"url": "https://codsen.com"
|
|
23
23
|
},
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
"script": "./dist/ranges-process-outside.umd.js",
|
|
27
|
+
"default": "./dist/ranges-process-outside.esm.js"
|
|
28
|
+
},
|
|
27
29
|
"types": "types/index.d.ts",
|
|
28
30
|
"scripts": {
|
|
29
31
|
"build": "rollup -c",
|
|
@@ -43,18 +45,20 @@
|
|
|
43
45
|
"pretest": "npm run build",
|
|
44
46
|
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
45
47
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
46
|
-
"unittest": "
|
|
48
|
+
"unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf",
|
|
47
49
|
"clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
|
|
48
50
|
"clean_types": "../../scripts/cleanTypes.js"
|
|
49
51
|
},
|
|
50
52
|
"tap": {
|
|
53
|
+
"check-coverage": false,
|
|
51
54
|
"coverage-report": [
|
|
52
55
|
"json-summary",
|
|
53
56
|
"text"
|
|
54
57
|
],
|
|
55
|
-
"
|
|
56
|
-
"--
|
|
57
|
-
"--
|
|
58
|
+
"node-arg": [
|
|
59
|
+
"--no-warnings",
|
|
60
|
+
"--experimental-loader",
|
|
61
|
+
"@istanbuljs/esm-loader-hook"
|
|
58
62
|
],
|
|
59
63
|
"timeout": 0
|
|
60
64
|
},
|
|
@@ -72,48 +76,51 @@
|
|
|
72
76
|
}
|
|
73
77
|
},
|
|
74
78
|
"dependencies": {
|
|
75
|
-
"@babel/runtime": "^7.
|
|
76
|
-
"ranges-crop": "^
|
|
77
|
-
"ranges-invert": "^
|
|
79
|
+
"@babel/runtime": "^7.15.4",
|
|
80
|
+
"ranges-crop": "^5.0.2",
|
|
81
|
+
"ranges-invert": "^5.0.2",
|
|
78
82
|
"runes": "^0.4.3"
|
|
79
83
|
},
|
|
80
84
|
"devDependencies": {
|
|
81
|
-
"@babel/cli": "^7.
|
|
82
|
-
"@babel/core": "^7.
|
|
83
|
-
"@babel/node": "^7.
|
|
84
|
-
"@babel/plugin-external-helpers": "^7.
|
|
85
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
86
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.
|
|
87
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
88
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
89
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
90
|
-
"@babel/preset-env": "^7.
|
|
91
|
-
"@babel/preset-typescript": "^7.
|
|
92
|
-
"@babel/register": "^7.
|
|
85
|
+
"@babel/cli": "^7.15.4",
|
|
86
|
+
"@babel/core": "^7.15.5",
|
|
87
|
+
"@babel/node": "^7.15.4",
|
|
88
|
+
"@babel/plugin-external-helpers": "^7.14.5",
|
|
89
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
90
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
|
|
91
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.15.6",
|
|
92
|
+
"@babel/plugin-proposal-optional-chaining": "^7.14.5",
|
|
93
|
+
"@babel/plugin-transform-runtime": "^7.15.0",
|
|
94
|
+
"@babel/preset-env": "^7.15.6",
|
|
95
|
+
"@babel/preset-typescript": "^7.15.0",
|
|
96
|
+
"@babel/register": "^7.15.3",
|
|
97
|
+
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
93
98
|
"@rollup/plugin-babel": "^5.3.0",
|
|
94
|
-
"@rollup/plugin-commonjs": "^
|
|
99
|
+
"@rollup/plugin-commonjs": "^20.0.0",
|
|
95
100
|
"@rollup/plugin-json": "^4.1.0",
|
|
96
|
-
"@rollup/plugin-node-resolve": "^
|
|
97
|
-
"@rollup/plugin-
|
|
98
|
-
"@rollup/plugin-
|
|
99
|
-
"@
|
|
100
|
-
"@types/node": "^14.14.37",
|
|
101
|
+
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
102
|
+
"@rollup/plugin-strip": "^2.1.0",
|
|
103
|
+
"@rollup/plugin-typescript": "^8.2.5",
|
|
104
|
+
"@types/node": "^16.9.1",
|
|
101
105
|
"@types/runes": "^0.4.1",
|
|
102
|
-
"@types/tap": "^
|
|
103
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
104
|
-
"@typescript-eslint/parser": "^4.
|
|
105
|
-
"core-js": "^3.
|
|
106
|
+
"@types/tap": "^15.0.5",
|
|
107
|
+
"@typescript-eslint/eslint-plugin": "^4.31.0",
|
|
108
|
+
"@typescript-eslint/parser": "^4.31.0",
|
|
109
|
+
"core-js": "^3.17.3",
|
|
106
110
|
"cross-env": "^7.0.3",
|
|
107
|
-
"eslint": "^7.
|
|
108
|
-
"lect": "^0.
|
|
109
|
-
"rollup": "^2.
|
|
111
|
+
"eslint": "^7.32.0",
|
|
112
|
+
"lect": "^0.18.2",
|
|
113
|
+
"rollup": "^2.56.3",
|
|
110
114
|
"rollup-plugin-ascii": "^0.0.3",
|
|
111
115
|
"rollup-plugin-banner": "^0.2.1",
|
|
112
116
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
113
|
-
"rollup-plugin-dts": "^
|
|
117
|
+
"rollup-plugin-dts": "^4.0.0",
|
|
114
118
|
"rollup-plugin-terser": "^7.0.2",
|
|
115
|
-
"tap": "^
|
|
116
|
-
"tslib": "^2.1
|
|
117
|
-
"typescript": "^4.
|
|
119
|
+
"tap": "^15.0.9",
|
|
120
|
+
"tslib": "^2.3.1",
|
|
121
|
+
"typescript": "^4.4.3"
|
|
122
|
+
},
|
|
123
|
+
"engines": {
|
|
124
|
+
"node": ">=12"
|
|
118
125
|
}
|
|
119
126
|
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name ranges-process-outside
|
|
3
|
-
* @fileoverview Iterate string considering ranges, as if they were already applied
|
|
4
|
-
* @version 4.0.16
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/ranges-process-outside/}
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
13
|
-
|
|
14
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
15
|
-
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
16
|
-
var runes = require('runes');
|
|
17
|
-
var rangesInvert = require('ranges-invert');
|
|
18
|
-
var rangesCrop = require('ranges-crop');
|
|
19
|
-
|
|
20
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
|
-
|
|
22
|
-
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
23
|
-
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
24
|
-
var runes__default = /*#__PURE__*/_interopDefaultLegacy(runes);
|
|
25
|
-
|
|
26
|
-
var version$1 = "4.0.16";
|
|
27
|
-
|
|
28
|
-
var version = version$1;
|
|
29
|
-
function rProcessOutside(originalStr, originalRanges, cb) {
|
|
30
|
-
var skipChecks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
31
|
-
if (typeof originalStr !== "string") {
|
|
32
|
-
if (originalStr === undefined) {
|
|
33
|
-
throw new Error("ranges-process-outside: [THROW_ID_01] the first input argument must be string! It's missing currently (undefined)!");
|
|
34
|
-
} else {
|
|
35
|
-
throw new Error("ranges-process-outside: [THROW_ID_02] the first input argument must be string! It was given as:\n".concat(JSON.stringify(originalStr, null, 4), " (type ").concat(_typeof__default['default'](originalStr), ")"));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (originalRanges && (!Array.isArray(originalRanges) || originalRanges.length && !Array.isArray(originalRanges[0]))) {
|
|
39
|
-
throw new Error("ranges-process-outside: [THROW_ID_03] the second input argument must be array of ranges or null! It was given as:\n".concat(JSON.stringify(originalRanges, null, 4), " (type ").concat(_typeof__default['default'](originalRanges), ")"));
|
|
40
|
-
}
|
|
41
|
-
if (typeof cb !== "function") {
|
|
42
|
-
throw new Error("ranges-process-outside: [THROW_ID_04] the third input argument must be a function! It was given as:\n".concat(JSON.stringify(cb, null, 4), " (type ").concat(_typeof__default['default'](cb), ")"));
|
|
43
|
-
}
|
|
44
|
-
function iterator(str, arrOfArrays) {
|
|
45
|
-
(arrOfArrays || []).forEach(function (_ref) {
|
|
46
|
-
var _ref2 = _slicedToArray__default['default'](_ref, 2),
|
|
47
|
-
fromIdx = _ref2[0],
|
|
48
|
-
toIdx = _ref2[1];
|
|
49
|
-
var _loop = function _loop(_i) {
|
|
50
|
-
var charLength = runes__default['default'](str.slice(_i))[0].length;
|
|
51
|
-
cb(_i, _i + charLength, function (offsetValue) {
|
|
52
|
-
/* istanbul ignore else */
|
|
53
|
-
if (offsetValue != null) {
|
|
54
|
-
_i += offsetValue;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
if (charLength && charLength > 1) {
|
|
58
|
-
_i += charLength - 1;
|
|
59
|
-
}
|
|
60
|
-
i = _i;
|
|
61
|
-
};
|
|
62
|
-
for (var i = fromIdx; i < toIdx; i++) {
|
|
63
|
-
_loop(i);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (originalRanges && originalRanges.length) {
|
|
68
|
-
var temp = rangesCrop.rCrop(rangesInvert.rInvert(skipChecks ? originalRanges : originalRanges, originalStr.length, {
|
|
69
|
-
skipChecks: !!skipChecks
|
|
70
|
-
}), originalStr.length);
|
|
71
|
-
iterator(originalStr, temp);
|
|
72
|
-
} else {
|
|
73
|
-
iterator(originalStr, [[0, originalStr.length]]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
exports.rProcessOutside = rProcessOutside;
|
|
78
|
-
exports.version = version;
|
|
@@ -1,531 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name ranges-process-outside
|
|
3
|
-
* @fileoverview Iterate string considering ranges, as if they were already applied
|
|
4
|
-
* @version 4.0.16
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/ranges-process-outside/}
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
(function (global, factory) {
|
|
11
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
12
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
13
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.rangesProcessOutside = {}));
|
|
14
|
-
}(this, (function (exports) { 'use strict';
|
|
15
|
-
|
|
16
|
-
const HIGH_SURROGATE_START = 0xd800;
|
|
17
|
-
const HIGH_SURROGATE_END = 0xdbff;
|
|
18
|
-
|
|
19
|
-
const LOW_SURROGATE_START = 0xdc00;
|
|
20
|
-
|
|
21
|
-
const REGIONAL_INDICATOR_START = 0x1f1e6;
|
|
22
|
-
const REGIONAL_INDICATOR_END = 0x1f1ff;
|
|
23
|
-
|
|
24
|
-
const FITZPATRICK_MODIFIER_START = 0x1f3fb;
|
|
25
|
-
const FITZPATRICK_MODIFIER_END = 0x1f3ff;
|
|
26
|
-
|
|
27
|
-
const VARIATION_MODIFIER_START = 0xfe00;
|
|
28
|
-
const VARIATION_MODIFIER_END = 0xfe0f;
|
|
29
|
-
|
|
30
|
-
const DIACRITICAL_MARKS_START = 0x20d0;
|
|
31
|
-
const DIACRITICAL_MARKS_END = 0x20ff;
|
|
32
|
-
|
|
33
|
-
const ZWJ = 0x200d;
|
|
34
|
-
|
|
35
|
-
const GRAPHEMS = [
|
|
36
|
-
0x0308, // ( ◌̈ ) COMBINING DIAERESIS
|
|
37
|
-
0x0937, // ( ष ) DEVANAGARI LETTER SSA
|
|
38
|
-
0x0937, // ( ष ) DEVANAGARI LETTER SSA
|
|
39
|
-
0x093F, // ( ि ) DEVANAGARI VOWEL SIGN I
|
|
40
|
-
0x093F, // ( ि ) DEVANAGARI VOWEL SIGN I
|
|
41
|
-
0x0BA8, // ( ந ) TAMIL LETTER NA
|
|
42
|
-
0x0BBF, // ( ி ) TAMIL VOWEL SIGN I
|
|
43
|
-
0x0BCD, // ( ◌்) TAMIL SIGN VIRAMA
|
|
44
|
-
0x0E31, // ( ◌ั ) THAI CHARACTER MAI HAN-AKAT
|
|
45
|
-
0x0E33, // ( ำ ) THAI CHARACTER SARA AM
|
|
46
|
-
0x0E40, // ( เ ) THAI CHARACTER SARA E
|
|
47
|
-
0x0E49, // ( เ ) THAI CHARACTER MAI THO
|
|
48
|
-
0x1100, // ( ᄀ ) HANGUL CHOSEONG KIYEOK
|
|
49
|
-
0x1161, // ( ᅡ ) HANGUL JUNGSEONG A
|
|
50
|
-
0x11A8 // ( ᆨ ) HANGUL JONGSEONG KIYEOK
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
function runes (string) {
|
|
54
|
-
if (typeof string !== 'string') {
|
|
55
|
-
throw new Error('string cannot be undefined or null')
|
|
56
|
-
}
|
|
57
|
-
const result = [];
|
|
58
|
-
let i = 0;
|
|
59
|
-
let increment = 0;
|
|
60
|
-
while (i < string.length) {
|
|
61
|
-
increment += nextUnits(i + increment, string);
|
|
62
|
-
if (isGraphem(string[i + increment])) {
|
|
63
|
-
increment++;
|
|
64
|
-
}
|
|
65
|
-
if (isVariationSelector(string[i + increment])) {
|
|
66
|
-
increment++;
|
|
67
|
-
}
|
|
68
|
-
if (isDiacriticalMark(string[i + increment])) {
|
|
69
|
-
increment++;
|
|
70
|
-
}
|
|
71
|
-
if (isZeroWidthJoiner(string[i + increment])) {
|
|
72
|
-
increment++;
|
|
73
|
-
continue
|
|
74
|
-
}
|
|
75
|
-
result.push(string.substring(i, i + increment));
|
|
76
|
-
i += increment;
|
|
77
|
-
increment = 0;
|
|
78
|
-
}
|
|
79
|
-
return result
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Decide how many code units make up the current character.
|
|
83
|
-
// BMP characters: 1 code unit
|
|
84
|
-
// Non-BMP characters (represented by surrogate pairs): 2 code units
|
|
85
|
-
// Emoji with skin-tone modifiers: 4 code units (2 code points)
|
|
86
|
-
// Country flags: 4 code units (2 code points)
|
|
87
|
-
// Variations: 2 code units
|
|
88
|
-
function nextUnits (i, string) {
|
|
89
|
-
const current = string[i];
|
|
90
|
-
// If we don't have a value that is part of a surrogate pair, or we're at
|
|
91
|
-
// the end, only take the value at i
|
|
92
|
-
if (!isFirstOfSurrogatePair(current) || i === string.length - 1) {
|
|
93
|
-
return 1
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const currentPair = current + string[i + 1];
|
|
97
|
-
let nextPair = string.substring(i + 2, i + 5);
|
|
98
|
-
|
|
99
|
-
// Country flags are comprised of two regional indicator symbols,
|
|
100
|
-
// each represented by a surrogate pair.
|
|
101
|
-
// See http://emojipedia.org/flags/
|
|
102
|
-
// If both pairs are regional indicator symbols, take 4
|
|
103
|
-
if (isRegionalIndicator(currentPair) && isRegionalIndicator(nextPair)) {
|
|
104
|
-
return 4
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// If the next pair make a Fitzpatrick skin tone
|
|
108
|
-
// modifier, take 4
|
|
109
|
-
// See http://emojipedia.org/modifiers/
|
|
110
|
-
// Technically, only some code points are meant to be
|
|
111
|
-
// combined with the skin tone modifiers. This function
|
|
112
|
-
// does not check the current pair to see if it is
|
|
113
|
-
// one of them.
|
|
114
|
-
if (isFitzpatrickModifier(nextPair)) {
|
|
115
|
-
return 4
|
|
116
|
-
}
|
|
117
|
-
return 2
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function isFirstOfSurrogatePair (string) {
|
|
121
|
-
return string && betweenInclusive(string[0].charCodeAt(0), HIGH_SURROGATE_START, HIGH_SURROGATE_END)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function isRegionalIndicator (string) {
|
|
125
|
-
return betweenInclusive(codePointFromSurrogatePair(string), REGIONAL_INDICATOR_START, REGIONAL_INDICATOR_END)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function isFitzpatrickModifier (string) {
|
|
129
|
-
return betweenInclusive(codePointFromSurrogatePair(string), FITZPATRICK_MODIFIER_START, FITZPATRICK_MODIFIER_END)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function isVariationSelector (string) {
|
|
133
|
-
return typeof string === 'string' && betweenInclusive(string.charCodeAt(0), VARIATION_MODIFIER_START, VARIATION_MODIFIER_END)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function isDiacriticalMark (string) {
|
|
137
|
-
return typeof string === 'string' && betweenInclusive(string.charCodeAt(0), DIACRITICAL_MARKS_START, DIACRITICAL_MARKS_END)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function isGraphem (string) {
|
|
141
|
-
return typeof string === 'string' && GRAPHEMS.indexOf(string.charCodeAt(0)) !== -1
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function isZeroWidthJoiner (string) {
|
|
145
|
-
return typeof string === 'string' && string.charCodeAt(0) === ZWJ
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function codePointFromSurrogatePair (pair) {
|
|
149
|
-
const highOffset = pair.charCodeAt(0) - HIGH_SURROGATE_START;
|
|
150
|
-
const lowOffset = pair.charCodeAt(1) - LOW_SURROGATE_START;
|
|
151
|
-
return (highOffset << 10) + lowOffset + 0x10000
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function betweenInclusive (value, lower, upper) {
|
|
155
|
-
return value >= lower && value <= upper
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function substring (string, start, width) {
|
|
159
|
-
const chars = runes(string);
|
|
160
|
-
if (start === undefined) {
|
|
161
|
-
return string
|
|
162
|
-
}
|
|
163
|
-
if (start >= chars.length) {
|
|
164
|
-
return ''
|
|
165
|
-
}
|
|
166
|
-
const rest = chars.length - start;
|
|
167
|
-
const stringWidth = width === undefined ? rest : width;
|
|
168
|
-
let endIndex = start + stringWidth;
|
|
169
|
-
if (endIndex > (start + rest)) {
|
|
170
|
-
endIndex = undefined;
|
|
171
|
-
}
|
|
172
|
-
return chars.slice(start, endIndex).join('')
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
var runes_1 = runes;
|
|
176
|
-
var substr = substring;
|
|
177
|
-
runes_1.substr = substr;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* @name ranges-sort
|
|
181
|
-
* @fileoverview Sort string index ranges
|
|
182
|
-
* @version 4.0.16
|
|
183
|
-
* @author Roy Revelt, Codsen Ltd
|
|
184
|
-
* @license MIT
|
|
185
|
-
* {@link https://codsen.com/os/ranges-sort/}
|
|
186
|
-
*/
|
|
187
|
-
const defaults$1 = {
|
|
188
|
-
strictlyTwoElementsInRangeArrays: false,
|
|
189
|
-
progressFn: null
|
|
190
|
-
};
|
|
191
|
-
function rSort(arrOfRanges, originalOptions) {
|
|
192
|
-
if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
|
|
193
|
-
return arrOfRanges;
|
|
194
|
-
}
|
|
195
|
-
const opts = { ...defaults$1,
|
|
196
|
-
...originalOptions
|
|
197
|
-
};
|
|
198
|
-
let culpritsIndex;
|
|
199
|
-
let culpritsLen;
|
|
200
|
-
if (opts.strictlyTwoElementsInRangeArrays && !arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
201
|
-
if (rangeArr.length !== 2) {
|
|
202
|
-
culpritsIndex = indx;
|
|
203
|
-
culpritsLen = rangeArr.length;
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
return true;
|
|
207
|
-
})) {
|
|
208
|
-
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!`);
|
|
209
|
-
}
|
|
210
|
-
if (!arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
211
|
-
if (!Number.isInteger(rangeArr[0]) || rangeArr[0] < 0 || !Number.isInteger(rangeArr[1]) || rangeArr[1] < 0) {
|
|
212
|
-
culpritsIndex = indx;
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
return true;
|
|
216
|
-
})) {
|
|
217
|
-
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!`);
|
|
218
|
-
}
|
|
219
|
-
const maxPossibleIterations = arrOfRanges.filter(range => range).length ** 2;
|
|
220
|
-
let counter = 0;
|
|
221
|
-
return Array.from(arrOfRanges).filter(range => range).sort((range1, range2) => {
|
|
222
|
-
if (opts.progressFn) {
|
|
223
|
-
counter += 1;
|
|
224
|
-
opts.progressFn(Math.floor(counter * 100 / maxPossibleIterations));
|
|
225
|
-
}
|
|
226
|
-
if (range1[0] === range2[0]) {
|
|
227
|
-
if (range1[1] < range2[1]) {
|
|
228
|
-
return -1;
|
|
229
|
-
}
|
|
230
|
-
if (range1[1] > range2[1]) {
|
|
231
|
-
return 1;
|
|
232
|
-
}
|
|
233
|
-
return 0;
|
|
234
|
-
}
|
|
235
|
-
if (range1[0] < range2[0]) {
|
|
236
|
-
return -1;
|
|
237
|
-
}
|
|
238
|
-
return 1;
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* @name ranges-merge
|
|
244
|
-
* @fileoverview Merge and sort string index ranges
|
|
245
|
-
* @version 7.0.16
|
|
246
|
-
* @author Roy Revelt, Codsen Ltd
|
|
247
|
-
* @license MIT
|
|
248
|
-
* {@link https://codsen.com/os/ranges-merge/}
|
|
249
|
-
*/
|
|
250
|
-
const defaults = {
|
|
251
|
-
mergeType: 1,
|
|
252
|
-
progressFn: null,
|
|
253
|
-
joinRangesThatTouchEdges: true
|
|
254
|
-
};
|
|
255
|
-
function rMerge(arrOfRanges, originalOpts) {
|
|
256
|
-
function isObj(something) {
|
|
257
|
-
return something && typeof something === "object" && !Array.isArray(something);
|
|
258
|
-
}
|
|
259
|
-
if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
let opts;
|
|
263
|
-
if (originalOpts) {
|
|
264
|
-
if (isObj(originalOpts)) {
|
|
265
|
-
opts = { ...defaults,
|
|
266
|
-
...originalOpts
|
|
267
|
-
};
|
|
268
|
-
if (opts.progressFn && isObj(opts.progressFn) && !Object.keys(opts.progressFn).length) {
|
|
269
|
-
opts.progressFn = null;
|
|
270
|
-
} else if (opts.progressFn && typeof opts.progressFn !== "function") {
|
|
271
|
-
throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof opts.progressFn}", equal to ${JSON.stringify(opts.progressFn, null, 4)}`);
|
|
272
|
-
}
|
|
273
|
-
if (opts.mergeType && +opts.mergeType !== 1 && +opts.mergeType !== 2) {
|
|
274
|
-
throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof opts.mergeType}", equal to ${JSON.stringify(opts.mergeType, null, 4)}`);
|
|
275
|
-
}
|
|
276
|
-
if (typeof opts.joinRangesThatTouchEdges !== "boolean") {
|
|
277
|
-
throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof opts.joinRangesThatTouchEdges}", equal to ${JSON.stringify(opts.joinRangesThatTouchEdges, null, 4)}`);
|
|
278
|
-
}
|
|
279
|
-
} else {
|
|
280
|
-
throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n${JSON.stringify(originalOpts, null, 4)} (type ${typeof originalOpts})`);
|
|
281
|
-
}
|
|
282
|
-
} else {
|
|
283
|
-
opts = { ...defaults
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
const filtered = arrOfRanges
|
|
287
|
-
.filter(range => range).map(subarr => [...subarr]).filter(
|
|
288
|
-
rangeArr => rangeArr[2] !== undefined || rangeArr[0] !== rangeArr[1]);
|
|
289
|
-
let sortedRanges;
|
|
290
|
-
let lastPercentageDone;
|
|
291
|
-
let percentageDone;
|
|
292
|
-
if (opts.progressFn) {
|
|
293
|
-
sortedRanges = rSort(filtered, {
|
|
294
|
-
progressFn: percentage => {
|
|
295
|
-
percentageDone = Math.floor(percentage / 5);
|
|
296
|
-
if (percentageDone !== lastPercentageDone) {
|
|
297
|
-
lastPercentageDone = percentageDone;
|
|
298
|
-
opts.progressFn(percentageDone);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
} else {
|
|
303
|
-
sortedRanges = rSort(filtered);
|
|
304
|
-
}
|
|
305
|
-
if (!sortedRanges) {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
const len = sortedRanges.length - 1;
|
|
309
|
-
for (let i = len; i > 0; i--) {
|
|
310
|
-
if (opts.progressFn) {
|
|
311
|
-
percentageDone = Math.floor((1 - i / len) * 78) + 21;
|
|
312
|
-
if (percentageDone !== lastPercentageDone && percentageDone > lastPercentageDone) {
|
|
313
|
-
lastPercentageDone = percentageDone;
|
|
314
|
-
opts.progressFn(percentageDone);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (sortedRanges[i][0] <= sortedRanges[i - 1][0] || !opts.joinRangesThatTouchEdges && sortedRanges[i][0] < sortedRanges[i - 1][1] || opts.joinRangesThatTouchEdges && sortedRanges[i][0] <= sortedRanges[i - 1][1]) {
|
|
318
|
-
sortedRanges[i - 1][0] = Math.min(sortedRanges[i][0], sortedRanges[i - 1][0]);
|
|
319
|
-
sortedRanges[i - 1][1] = Math.max(sortedRanges[i][1], sortedRanges[i - 1][1]);
|
|
320
|
-
if (sortedRanges[i][2] !== undefined && (sortedRanges[i - 1][0] >= sortedRanges[i][0] || sortedRanges[i - 1][1] <= sortedRanges[i][1])) {
|
|
321
|
-
if (sortedRanges[i - 1][2] !== null) {
|
|
322
|
-
if (sortedRanges[i][2] === null && sortedRanges[i - 1][2] !== null) {
|
|
323
|
-
sortedRanges[i - 1][2] = null;
|
|
324
|
-
} else if (sortedRanges[i - 1][2] != null) {
|
|
325
|
-
if (+opts.mergeType === 2 && sortedRanges[i - 1][0] === sortedRanges[i][0]) {
|
|
326
|
-
sortedRanges[i - 1][2] = sortedRanges[i][2];
|
|
327
|
-
} else {
|
|
328
|
-
sortedRanges[i - 1][2] += sortedRanges[i][2];
|
|
329
|
-
}
|
|
330
|
-
} else {
|
|
331
|
-
sortedRanges[i - 1][2] = sortedRanges[i][2];
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
sortedRanges.splice(i, 1);
|
|
336
|
-
i = sortedRanges.length;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return sortedRanges.length ? sortedRanges : null;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* @name ranges-crop
|
|
344
|
-
* @fileoverview Crop array of ranges when they go beyond the reference string's length
|
|
345
|
-
* @version 4.0.16
|
|
346
|
-
* @author Roy Revelt, Codsen Ltd
|
|
347
|
-
* @license MIT
|
|
348
|
-
* {@link https://codsen.com/os/ranges-crop/}
|
|
349
|
-
*/
|
|
350
|
-
function rCrop(arrOfRanges, strLen) {
|
|
351
|
-
if (arrOfRanges === null) {
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
if (!Array.isArray(arrOfRanges)) {
|
|
355
|
-
throw new TypeError(`ranges-crop: [THROW_ID_01] The first input's argument must be an array, consisting of range arrays! Currently its type is: ${typeof arrOfRanges}, equal to: ${JSON.stringify(arrOfRanges, null, 4)}`);
|
|
356
|
-
}
|
|
357
|
-
if (!Number.isInteger(strLen)) {
|
|
358
|
-
throw new TypeError(`ranges-crop: [THROW_ID_02] The second input's argument must be a natural number or zero (coming from String.length)! Currently its type is: ${typeof strLen}, equal to: ${JSON.stringify(strLen, null, 4)}`);
|
|
359
|
-
}
|
|
360
|
-
if (!arrOfRanges.filter(range => range).length) {
|
|
361
|
-
return arrOfRanges.filter(range => range);
|
|
362
|
-
}
|
|
363
|
-
let culpritsIndex = 0;
|
|
364
|
-
if (!arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
365
|
-
if (!Number.isInteger(rangeArr[0]) || !Number.isInteger(rangeArr[1])) {
|
|
366
|
-
culpritsIndex = indx;
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
return true;
|
|
370
|
-
})) {
|
|
371
|
-
if (Array.isArray(arrOfRanges) && typeof arrOfRanges[0] === "number" && typeof arrOfRanges[1] === "number") {
|
|
372
|
-
throw new TypeError(`ranges-crop: [THROW_ID_03] The first argument should be AN ARRAY OF RANGES, not a single range! Currently arrOfRanges = ${JSON.stringify(arrOfRanges, null, 0)}!`);
|
|
373
|
-
}
|
|
374
|
-
throw new TypeError(`ranges-crop: [THROW_ID_04] The first argument should be AN ARRAY OF ARRAYS! Each sub-array means string slice indexes. In our case, here ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 0)}) does not consist of only natural numbers!`);
|
|
375
|
-
}
|
|
376
|
-
if (!arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
377
|
-
if (rangeArr[2] != null && typeof rangeArr[2] !== "string") {
|
|
378
|
-
culpritsIndex = indx;
|
|
379
|
-
return false;
|
|
380
|
-
}
|
|
381
|
-
return true;
|
|
382
|
-
})) {
|
|
383
|
-
throw new TypeError(`ranges-crop: [THROW_ID_05] The third argument, if present at all, should be of a string-type or null. Currently the ${culpritsIndex}th range ${JSON.stringify(arrOfRanges[culpritsIndex], null, 0)} has a argument in the range of a type ${typeof arrOfRanges[culpritsIndex][2]}`);
|
|
384
|
-
}
|
|
385
|
-
const res = (rMerge(arrOfRanges) || []).filter(singleRangeArr => singleRangeArr[0] <= strLen && (singleRangeArr[2] != undefined || singleRangeArr[0] < strLen)).map(singleRangeArr => {
|
|
386
|
-
if (singleRangeArr[1] > strLen) {
|
|
387
|
-
if (singleRangeArr[2] != undefined) {
|
|
388
|
-
return [singleRangeArr[0], strLen, singleRangeArr[2]];
|
|
389
|
-
}
|
|
390
|
-
return [singleRangeArr[0], strLen];
|
|
391
|
-
}
|
|
392
|
-
return singleRangeArr;
|
|
393
|
-
});
|
|
394
|
-
return res === [] ? null : res;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* @name ranges-invert
|
|
399
|
-
* @fileoverview Invert string index ranges
|
|
400
|
-
* @version 4.0.16
|
|
401
|
-
* @author Roy Revelt, Codsen Ltd
|
|
402
|
-
* @license MIT
|
|
403
|
-
* {@link https://codsen.com/os/ranges-invert/}
|
|
404
|
-
*/
|
|
405
|
-
function rInvert(arrOfRanges, strLen, originalOptions) {
|
|
406
|
-
if (!Array.isArray(arrOfRanges) && arrOfRanges !== null) {
|
|
407
|
-
throw new TypeError(`ranges-invert: [THROW_ID_01] Input's first argument must be an array, consisting of range arrays! Currently its type is: ${typeof arrOfRanges}, equal to: ${JSON.stringify(arrOfRanges, null, 4)}`);
|
|
408
|
-
}
|
|
409
|
-
if (!Number.isInteger(strLen) || strLen < 0) {
|
|
410
|
-
throw new TypeError(`ranges-invert: [THROW_ID_02] Input's second argument must be a natural number or zero (coming from String.length)! Currently its type is: ${typeof strLen}, equal to: ${JSON.stringify(strLen, null, 4)}`);
|
|
411
|
-
}
|
|
412
|
-
if (Array.isArray(arrOfRanges) && typeof arrOfRanges[0] === "number" && typeof arrOfRanges[1] === "number") {
|
|
413
|
-
throw new TypeError(`ranges-invert: [THROW_ID_07] The first argument should be AN ARRAY OF RANGES, not a single range! Currently arrOfRanges = ${JSON.stringify(arrOfRanges, null, 0)}!`);
|
|
414
|
-
}
|
|
415
|
-
if (!Array.isArray(arrOfRanges) || !arrOfRanges.filter(range => Array.isArray(range) && range[0] !== range[1]).length || !strLen) {
|
|
416
|
-
if (!strLen) {
|
|
417
|
-
return null;
|
|
418
|
-
}
|
|
419
|
-
return [[0, strLen]];
|
|
420
|
-
}
|
|
421
|
-
const defaults = {
|
|
422
|
-
strictlyTwoElementsInRangeArrays: false,
|
|
423
|
-
skipChecks: false
|
|
424
|
-
};
|
|
425
|
-
const opts = { ...defaults,
|
|
426
|
-
...originalOptions
|
|
427
|
-
};
|
|
428
|
-
let culpritsIndex = 0;
|
|
429
|
-
let culpritsLen;
|
|
430
|
-
if (!opts.skipChecks && opts.strictlyTwoElementsInRangeArrays && !arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
431
|
-
if (rangeArr.length !== 2) {
|
|
432
|
-
culpritsIndex = indx;
|
|
433
|
-
culpritsLen = rangeArr.length;
|
|
434
|
-
return false;
|
|
435
|
-
}
|
|
436
|
-
return true;
|
|
437
|
-
})) {
|
|
438
|
-
throw new TypeError(`ranges-invert: [THROW_ID_04] Because opts.strictlyTwoElementsInRangeArrays was enabled, all ranges must be strictly two-element-long. However, the ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 0)}) has not two but ${culpritsLen} elements!`);
|
|
439
|
-
}
|
|
440
|
-
if (!opts.skipChecks && !arrOfRanges.every((rangeArr, indx) => {
|
|
441
|
-
if (!Number.isInteger(rangeArr[0]) || rangeArr[0] < 0 || !Number.isInteger(rangeArr[1]) || rangeArr[1] < 0) {
|
|
442
|
-
culpritsIndex = indx;
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
445
|
-
return true;
|
|
446
|
-
})) {
|
|
447
|
-
throw new TypeError(`ranges-invert: [THROW_ID_05] The first argument should be AN ARRAY OF ARRAYS! Each sub-array means string slice indexes. In our case, here ${culpritsIndex + 1}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 0)}) does not consist of only natural numbers!`);
|
|
448
|
-
}
|
|
449
|
-
let prep;
|
|
450
|
-
if (!opts.skipChecks) {
|
|
451
|
-
prep = rMerge(arrOfRanges.filter(rangeArr => rangeArr[0] !== rangeArr[1]));
|
|
452
|
-
} else {
|
|
453
|
-
prep = arrOfRanges.filter(rangeArr => rangeArr[0] !== rangeArr[1]);
|
|
454
|
-
}
|
|
455
|
-
const res = prep.reduce((accum, currArr, i, arr) => {
|
|
456
|
-
const res2 = [];
|
|
457
|
-
if (i === 0 && arr[0][0] !== 0) {
|
|
458
|
-
res2.push([0, arr[0][0]]);
|
|
459
|
-
}
|
|
460
|
-
const endingIndex = i < arr.length - 1 ? arr[i + 1][0] : strLen;
|
|
461
|
-
if (currArr[1] !== endingIndex) {
|
|
462
|
-
if (opts.skipChecks && currArr[1] > endingIndex) {
|
|
463
|
-
throw new TypeError(`ranges-invert: [THROW_ID_08] The checking (opts.skipChecks) is off and input ranges were not sorted! We nearly wrote range [${currArr[1]}, ${endingIndex}] which is backwards. For investigation, whole ranges array is:\n${JSON.stringify(arr, null, 0)}`);
|
|
464
|
-
}
|
|
465
|
-
res2.push([currArr[1], endingIndex]);
|
|
466
|
-
}
|
|
467
|
-
return accum.concat(res2);
|
|
468
|
-
}, []);
|
|
469
|
-
return rCrop(res, strLen);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
var version$1 = "4.0.16";
|
|
473
|
-
|
|
474
|
-
const version = version$1;
|
|
475
|
-
function rProcessOutside(originalStr, originalRanges, cb, skipChecks = false) {
|
|
476
|
-
//
|
|
477
|
-
// insurance:
|
|
478
|
-
//
|
|
479
|
-
if (typeof originalStr !== "string") {
|
|
480
|
-
if (originalStr === undefined) {
|
|
481
|
-
throw new Error(`ranges-process-outside: [THROW_ID_01] the first input argument must be string! It's missing currently (undefined)!`);
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
throw new Error(`ranges-process-outside: [THROW_ID_02] the first input argument must be string! It was given as:\n${JSON.stringify(originalStr, null, 4)} (type ${typeof originalStr})`);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (originalRanges &&
|
|
488
|
-
(!Array.isArray(originalRanges) ||
|
|
489
|
-
(originalRanges.length && !Array.isArray(originalRanges[0])))) {
|
|
490
|
-
throw new Error(`ranges-process-outside: [THROW_ID_03] the second input argument must be array of ranges or null! It was given as:\n${JSON.stringify(originalRanges, null, 4)} (type ${typeof originalRanges})`);
|
|
491
|
-
}
|
|
492
|
-
if (typeof cb !== "function") {
|
|
493
|
-
throw new Error(`ranges-process-outside: [THROW_ID_04] the third input argument must be a function! It was given as:\n${JSON.stringify(cb, null, 4)} (type ${typeof cb})`);
|
|
494
|
-
}
|
|
495
|
-
// separate the iterator because it might be called with inverted ranges or
|
|
496
|
-
// with separately calculated "everything" if the ranges are empty/falsey
|
|
497
|
-
function iterator(str, arrOfArrays) {
|
|
498
|
-
(arrOfArrays || []).forEach(([fromIdx, toIdx]) => {
|
|
499
|
-
for (let i = fromIdx; i < toIdx; i++) {
|
|
500
|
-
const charLength = runes_1(str.slice(i))[0].length;
|
|
501
|
-
cb(i, i + charLength, (offsetValue) => {
|
|
502
|
-
/* istanbul ignore else */
|
|
503
|
-
if (offsetValue != null) {
|
|
504
|
-
i += offsetValue;
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
if (charLength && charLength > 1) {
|
|
508
|
-
i += charLength - 1;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
if (originalRanges && originalRanges.length) {
|
|
514
|
-
// if ranges are given, invert and run callback against each character
|
|
515
|
-
const temp = rCrop(rInvert(skipChecks ? originalRanges : originalRanges, originalStr.length, {
|
|
516
|
-
skipChecks: !!skipChecks,
|
|
517
|
-
}), originalStr.length);
|
|
518
|
-
iterator(originalStr, temp);
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
// otherwise, run callback on everything
|
|
522
|
-
iterator(originalStr, [[0, originalStr.length]]);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
exports.rProcessOutside = rProcessOutside;
|
|
527
|
-
exports.version = version;
|
|
528
|
-
|
|
529
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
530
|
-
|
|
531
|
-
})));
|