ranges-iterate 3.0.5 → 3.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-iterate.esm.js +59 -56
- package/dist/ranges-iterate.umd.js +2 -2
- package/package.json +21 -25
|
@@ -1,78 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-iterate
|
|
3
3
|
* @fileoverview Iterate a string and any changes within given string index ranges
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.6
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ranges-iterate/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var version$1 = "3.0.
|
|
10
|
+
var version$1 = "3.0.6";
|
|
11
11
|
|
|
12
12
|
const version = version$1;
|
|
13
13
|
function rIterate(str, originalRanges, cb, offset = 0) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} else if (!str.length) {
|
|
17
|
-
throw new TypeError(`ranges-iterate: [THROW_ID_02] Input string must be non-empty!`);
|
|
18
|
-
}
|
|
19
|
-
if (originalRanges && !Array.isArray(originalRanges)) {
|
|
20
|
-
throw new TypeError(`ranges-iterate: [THROW_ID_03] Input ranges must be an array, consisting of zero or more arrays! Currently its type is: ${typeof originalRanges}, equal to: ${JSON.stringify(originalRanges, null, 0)}`);
|
|
21
|
-
}
|
|
22
|
-
if (!cb) {
|
|
23
|
-
throw new TypeError(`ranges-iterate: [THROW_ID_04] You should provide a callback function as third input argument!`);
|
|
24
|
-
} else if (typeof cb !== "function") {
|
|
25
|
-
throw new TypeError(`ranges-iterate: [THROW_ID_05] The calllback function (third input argument) must be a function. It was given as: ${typeof cb}, equal to: ${JSON.stringify(cb, null, 0)}`);
|
|
26
|
-
}
|
|
27
|
-
if (originalRanges === null || !originalRanges.length) {
|
|
28
|
-
for (let i = 0; i < str.length; i++) {
|
|
29
|
-
cb({
|
|
30
|
-
i,
|
|
31
|
-
val: str[i]
|
|
32
|
-
});
|
|
14
|
+
if (typeof str !== "string") {
|
|
15
|
+
throw new TypeError(`ranges-iterate: [THROW_ID_01] Input string must be a string! It was given as ${typeof str}, equal to: ${JSON.stringify(str, null, 0)}`);
|
|
33
16
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
val: str[finalIdx]
|
|
46
|
-
});
|
|
47
|
-
}
|
|
17
|
+
else if (!str.length) {
|
|
18
|
+
throw new TypeError(`ranges-iterate: [THROW_ID_02] Input string must be non-empty!`);
|
|
19
|
+
}
|
|
20
|
+
if (originalRanges && !Array.isArray(originalRanges)) {
|
|
21
|
+
throw new TypeError(`ranges-iterate: [THROW_ID_03] Input ranges must be an array, consisting of zero or more arrays! Currently its type is: ${typeof originalRanges}, equal to: ${JSON.stringify(originalRanges, null, 0)}`);
|
|
22
|
+
}
|
|
23
|
+
if (!cb) {
|
|
24
|
+
throw new TypeError(`ranges-iterate: [THROW_ID_04] You should provide a callback function as third input argument!`);
|
|
25
|
+
}
|
|
26
|
+
else if (typeof cb !== "function") {
|
|
27
|
+
throw new TypeError(`ranges-iterate: [THROW_ID_05] The calllback function (third input argument) must be a function. It was given as: ${typeof cb}, equal to: ${JSON.stringify(cb, null, 0)}`);
|
|
48
28
|
}
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
if (rangeArr[2]) {
|
|
52
|
-
for (let y = 0, len = rangeArr[2].length; y < len; y++) {
|
|
29
|
+
if (originalRanges === null || !originalRanges.length) {
|
|
30
|
+
for (let i = 0; i < str.length; i++) {
|
|
53
31
|
cb({
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
i,
|
|
33
|
+
val: str[i],
|
|
56
34
|
});
|
|
57
|
-
finalIdx += 1;
|
|
58
|
-
}
|
|
59
35
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let
|
|
64
|
-
|
|
65
|
-
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const ranges = Array.from(originalRanges);
|
|
39
|
+
let currentIdx = offset;
|
|
40
|
+
let finalIdx = offset;
|
|
41
|
+
if (finalIdx < ranges[0][0]) {
|
|
42
|
+
for (; finalIdx < ranges[0][0]; finalIdx++, currentIdx++) {
|
|
43
|
+
if (!str[finalIdx]) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
cb({
|
|
47
|
+
i: finalIdx,
|
|
48
|
+
val: str[finalIdx],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
66
51
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
52
|
+
if (ranges[0][0] <= currentIdx) {
|
|
53
|
+
ranges.forEach((rangeArr, rangeArrIdx) => {
|
|
54
|
+
if (rangeArr[2]) {
|
|
55
|
+
for (let y = 0, len = rangeArr[2].length; y < len; y++) {
|
|
56
|
+
cb({
|
|
57
|
+
i: finalIdx,
|
|
58
|
+
val: rangeArr[2][y],
|
|
59
|
+
});
|
|
60
|
+
finalIdx += 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
while (currentIdx < rangeArr[1]) {
|
|
64
|
+
currentIdx += 1;
|
|
65
|
+
}
|
|
66
|
+
let loopUntil = str.length;
|
|
67
|
+
if (ranges[rangeArrIdx + 1]) {
|
|
68
|
+
loopUntil = ranges[rangeArrIdx + 1][0];
|
|
69
|
+
}
|
|
70
|
+
for (; currentIdx < loopUntil; finalIdx++, currentIdx++) {
|
|
71
|
+
cb({
|
|
72
|
+
i: finalIdx,
|
|
73
|
+
val: str[currentIdx],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
72
77
|
}
|
|
73
|
-
});
|
|
74
78
|
}
|
|
75
|
-
}
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
export { rIterate, version };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-iterate
|
|
3
3
|
* @fileoverview Iterate a string and any changes within given string index ranges
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.6
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ranges-iterate/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).rangesIterate={})}(this,(function(e){"use strict";e.rIterate=function(e,t,r,n=0){if("string"!=typeof e)throw new TypeError(`ranges-iterate: [THROW_ID_01] Input string must be a string! It was given as ${typeof e}, equal to: ${JSON.stringify(e,null,0)}`);if(!e.length)throw new TypeError("ranges-iterate: [THROW_ID_02] Input string must be non-empty!");if(t&&!Array.isArray(t))throw new TypeError(`ranges-iterate: [THROW_ID_03] Input ranges must be an array, consisting of zero or more arrays! Currently its type is: ${typeof t}, equal to: ${JSON.stringify(t,null,0)}`);if(!r)throw new TypeError("ranges-iterate: [THROW_ID_04] You should provide a callback function as third input argument!");if("function"!=typeof r)throw new TypeError(`ranges-iterate: [THROW_ID_05] The calllback function (third input argument) must be a function. It was given as: ${typeof r}, equal to: ${JSON.stringify(r,null,0)}`);if(null!==t&&t.length){const i=Array.from(t);let o=n,a=n;if(a<i[0][0])for(;a<i[0][0]&&e[a];a++,o++)r({i:a,val:e[a]});i[0][0]<=o&&i.forEach(((t,n)=>{if(t[2])for(let e=0,n=t[2].length;e<n;e++)r({i:a,val:t[2][e]}),a+=1;for(;o<t[1];)o+=1;let f=e.length;for(i[n+1]&&(f=i[n+1][0]);o<f;a++,o++)r({i:a,val:e[o]})}))}else for(let t=0;t<e.length;t++)r({i:t,val:e[t]})},e.version="3.0.
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).rangesIterate={})}(this,(function(e){"use strict";e.rIterate=function(e,t,r,n=0){if("string"!=typeof e)throw new TypeError(`ranges-iterate: [THROW_ID_01] Input string must be a string! It was given as ${typeof e}, equal to: ${JSON.stringify(e,null,0)}`);if(!e.length)throw new TypeError("ranges-iterate: [THROW_ID_02] Input string must be non-empty!");if(t&&!Array.isArray(t))throw new TypeError(`ranges-iterate: [THROW_ID_03] Input ranges must be an array, consisting of zero or more arrays! Currently its type is: ${typeof t}, equal to: ${JSON.stringify(t,null,0)}`);if(!r)throw new TypeError("ranges-iterate: [THROW_ID_04] You should provide a callback function as third input argument!");if("function"!=typeof r)throw new TypeError(`ranges-iterate: [THROW_ID_05] The calllback function (third input argument) must be a function. It was given as: ${typeof r}, equal to: ${JSON.stringify(r,null,0)}`);if(null!==t&&t.length){const i=Array.from(t);let o=n,a=n;if(a<i[0][0])for(;a<i[0][0]&&e[a];a++,o++)r({i:a,val:e[a]});i[0][0]<=o&&i.forEach(((t,n)=>{if(t[2])for(let e=0,n=t[2].length;e<n;e++)r({i:a,val:t[2][e]}),a+=1;for(;o<t[1];)o+=1;let f=e.length;for(i[n+1]&&(f=i[n+1][0]);o<f;a++,o++)r({i:a,val:e[o]})}))}else for(let t=0;t<e.length;t++)r({i:t,val:e[t]})},e.version="3.0.6",Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ranges-iterate",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "Iterate a string and any changes within given string index ranges",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -34,13 +34,12 @@
|
|
|
34
34
|
"types": "types/index.d.ts",
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "rollup -c",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
37
|
+
"build:esbuild": "node '../../scripts/esbuild.js'",
|
|
38
|
+
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
39
|
+
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
|
|
39
40
|
"clean_types": "../../scripts/cleanTypes.js",
|
|
40
41
|
"dev": "rollup -c --dev",
|
|
41
42
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
42
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
43
|
-
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
44
43
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
45
44
|
"lect": "lect",
|
|
46
45
|
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
|
|
@@ -49,17 +48,14 @@
|
|
|
49
48
|
"republish": "npm publish || :",
|
|
50
49
|
"tap": "tap",
|
|
51
50
|
"pretest": "npm run build",
|
|
52
|
-
"test": "npm run
|
|
51
|
+
"test": "npm run test:ci && npm run perf",
|
|
52
|
+
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
53
53
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
54
54
|
"tsc": "tsc",
|
|
55
|
-
"unittest": "tap --no-only --
|
|
55
|
+
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
56
56
|
},
|
|
57
57
|
"tap": {
|
|
58
58
|
"check-coverage": false,
|
|
59
|
-
"coverage-report": [
|
|
60
|
-
"json-summary",
|
|
61
|
-
"text"
|
|
62
|
-
],
|
|
63
59
|
"node-arg": [
|
|
64
60
|
"--no-warnings",
|
|
65
61
|
"--experimental-loader",
|
|
@@ -82,7 +78,7 @@
|
|
|
82
78
|
}
|
|
83
79
|
},
|
|
84
80
|
"dependencies": {
|
|
85
|
-
"@babel/runtime": "^7.16.
|
|
81
|
+
"@babel/runtime": "^7.16.3"
|
|
86
82
|
},
|
|
87
83
|
"devDependencies": {
|
|
88
84
|
"@babel/cli": "^7.16.0",
|
|
@@ -93,8 +89,8 @@
|
|
|
93
89
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
94
90
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
95
91
|
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
96
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
97
|
-
"@babel/preset-env": "^7.16.
|
|
92
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
93
|
+
"@babel/preset-env": "^7.16.4",
|
|
98
94
|
"@babel/preset-typescript": "^7.16.0",
|
|
99
95
|
"@babel/register": "^7.16.0",
|
|
100
96
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
@@ -104,27 +100,27 @@
|
|
|
104
100
|
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
105
101
|
"@rollup/plugin-strip": "^2.1.0",
|
|
106
102
|
"@rollup/plugin-typescript": "^8.3.0",
|
|
107
|
-
"@types/node": "^16.11.
|
|
103
|
+
"@types/node": "^16.11.9",
|
|
108
104
|
"@types/tap": "^15.0.5",
|
|
109
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
110
|
-
"@typescript-eslint/parser": "^5.
|
|
105
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
106
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
111
107
|
"core-js": "^3.19.1",
|
|
112
108
|
"cross-env": "^7.0.3",
|
|
113
|
-
"eslint": "^8.
|
|
114
|
-
"lect": "^0.18.
|
|
115
|
-
"ranges-apply": "^6.0.
|
|
116
|
-
"ranges-merge": "^8.0.
|
|
117
|
-
"rollup": "^2.
|
|
109
|
+
"eslint": "^8.3.0",
|
|
110
|
+
"lect": "^0.18.6",
|
|
111
|
+
"ranges-apply": "^6.0.6",
|
|
112
|
+
"ranges-merge": "^8.0.6",
|
|
113
|
+
"rollup": "^2.60.0",
|
|
118
114
|
"rollup-plugin-ascii": "^0.0.3",
|
|
119
115
|
"rollup-plugin-banner": "^0.2.1",
|
|
120
116
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
121
117
|
"rollup-plugin-dts": "^4.0.1",
|
|
122
118
|
"rollup-plugin-terser": "^7.0.2",
|
|
123
|
-
"tap": "^15.
|
|
119
|
+
"tap": "^15.1.2",
|
|
124
120
|
"tslib": "^2.3.1",
|
|
125
|
-
"typescript": "^4.
|
|
121
|
+
"typescript": "^4.5.2"
|
|
126
122
|
},
|
|
127
123
|
"engines": {
|
|
128
|
-
"node": ">=
|
|
124
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
129
125
|
}
|
|
130
126
|
}
|