ranges-iterate 3.0.6 → 3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-2021 Roy Revelt and other contributors
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
- This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:
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, `2.1.0`.
30
30
 
31
31
  ```bash
32
32
  npm i ranges-iterate
33
33
  ```
34
34
 
35
- If you need a legacy version which works with `require`, use version 2.1.0
36
-
37
35
  ## Quick Take
38
36
 
39
37
  ```js
40
38
  import { strict as assert } from "assert";
39
+
41
40
  import { rIterate } from "ranges-iterate";
42
41
 
43
42
  // Ranges in the following example "punches out" a "hole" from `a` to `g`
@@ -62,7 +61,7 @@ assert.deepEqual(gathered, [
62
61
 
63
62
  ## Documentation
64
63
 
65
- Please [visit codsen.com](https://codsen.com/os/ranges-iterate/) for a full description of the API and examples.
64
+ Please [visit codsen.com](https://codsen.com/os/ranges-iterate/) for a full description of the API.
66
65
 
67
66
  ## Contributing
68
67
 
@@ -72,6 +71,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
72
71
 
73
72
  MIT License
74
73
 
75
- Copyright (c) 2010-2021 Roy Revelt and other contributors
74
+ Copyright (c) 2010-2022 Roy Revelt and other contributors
76
75
 
77
76
  <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">
@@ -1,81 +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.6
4
+ * @version 3.0.12
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.6";
11
-
12
- const version = version$1;
13
- function rIterate(str, originalRanges, cb, offset = 0) {
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)}`);
16
- }
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)}`);
28
- }
29
- if (originalRanges === null || !originalRanges.length) {
30
- for (let i = 0; i < str.length; i++) {
31
- cb({
32
- i,
33
- val: str[i],
34
- });
35
- }
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
- }
51
- }
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
- });
77
- }
78
- }
79
- }
80
-
81
- export { rIterate, version };
10
+ var c="3.0.12";var f=c;function b(r,o,n,a=0){if(typeof r!="string")throw new TypeError(`ranges-iterate: [THROW_ID_01] Input string must be a string! It was given as ${typeof r}, equal to: ${JSON.stringify(r,null,0)}`);if(!r.length)throw new TypeError("ranges-iterate: [THROW_ID_02] Input string must be non-empty!");if(o&&!Array.isArray(o))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 o}, equal to: ${JSON.stringify(o,null,0)}`);if(n){if(typeof n!="function")throw new TypeError(`ranges-iterate: [THROW_ID_05] The calllback function (third input argument) must be a function. It was given as: ${typeof n}, equal to: ${JSON.stringify(n,null,0)}`)}else throw new TypeError("ranges-iterate: [THROW_ID_04] You should provide a callback function as third input argument!");if(o===null||!o.length)for(let e=0;e<r.length;e++)n({i:e,val:r[e]});else{let e=Array.from(o),i=a,t=a;if(t<e[0][0])for(;t<e[0][0]&&r[t];t++,i++)n({i:t,val:r[t]});e[0][0]<=i&&e.forEach((s,u)=>{if(s[2])for(let l=0,p=s[2].length;l<p;l++)n({i:t,val:s[2][l]}),t+=1;for(;i<s[1];)i+=1;let $=r.length;for(e[u+1]&&($=e[u+1][0]);i<$;t++,i++)n({i:t,val:r[i]})})}}export{b as rIterate,f as 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.6
4
+ * @version 3.0.12
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.6",Object.defineProperty(e,"__esModule",{value:!0})}));
10
+ var rangesIterate=(()=>{var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var b=e=>u(e,"__esModule",{value:!0});var y=(e,r)=>{for(var t in r)u(e,t,{get:r[t],enumerable:!0})},x=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of g(r))!f.call(e,n)&&(t||n!=="default")&&u(e,n,{get:()=>r[n],enumerable:!(s=m(r,n))||s.enumerable});return e};var I=(e=>(r,t)=>e&&e.get(r)||(t=x(b({}),r,1),e&&e.set(r,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var D={};y(D,{rIterate:()=>v,version:()=>E});var p="3.0.12";var E=p;function v(e,r,t,s=0){if(typeof e!="string")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(r&&!Array.isArray(r))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 r}, equal to: ${JSON.stringify(r,null,0)}`);if(t){if(typeof t!="function")throw new TypeError(`ranges-iterate: [THROW_ID_05] The calllback function (third input argument) must be a function. It was given as: ${typeof t}, equal to: ${JSON.stringify(t,null,0)}`)}else throw new TypeError("ranges-iterate: [THROW_ID_04] You should provide a callback function as third input argument!");if(r===null||!r.length)for(let n=0;n<e.length;n++)t({i:n,val:e[n]});else{let n=Array.from(r),i=s,o=s;if(o<n[0][0])for(;o<n[0][0]&&e[o];o++,i++)t({i:o,val:e[o]});n[0][0]<=i&&n.forEach((l,$)=>{if(l[2])for(let a=0,d=l[2].length;a<d;a++)t({i:o,val:l[2][a]}),o+=1;for(;i<l[1];)i+=1;let c=e.length;for(n[$+1]&&(c=n[$+1][0]);i<c;o++,i++)t({i:o,val:e[i]})})}}return I(D);})();
@@ -1,6 +1,7 @@
1
1
  // Quick Take
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { rIterate } from "../dist/ranges-iterate.esm.js";
5
6
 
6
7
  // Ranges in the following example "punches out" a "hole" from `a` to `g`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ranges-iterate",
3
- "version": "3.0.6",
3
+ "version": "3.0.12",
4
4
  "description": "Iterate a string and any changes within given string index ranges",
5
5
  "keywords": [
6
6
  "array",
@@ -33,94 +33,41 @@
33
33
  },
34
34
  "types": "types/index.d.ts",
35
35
  "scripts": {
36
- "build": "rollup -c",
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",
40
- "clean_types": "../../scripts/cleanTypes.js",
41
- "dev": "rollup -c --dev",
42
- "devunittest": "npm run dev && tap --only -R 'base'",
43
- "format": "npm run lect && npm run prettier && npm run lint",
44
- "lect": "lect",
45
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
46
- "perf": "node perf/check",
47
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
48
- "republish": "npm publish || :",
49
- "tap": "tap",
50
- "pretest": "npm run build",
51
- "test": "npm run test:ci && npm run perf",
52
- "test:ci": "npm run unittest && npm run test:examples && npm run format",
53
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
54
- "tsc": "tsc",
55
- "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
36
+ "build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
37
+ "dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
38
+ "devtest": "c8 yarn run unit && yarn run examples && yarn run lint",
39
+ "dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
40
+ "examples": "node '../../ops/scripts/run-examples.js'",
41
+ "lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
42
+ "letspublish": "yarn publish || :",
43
+ "lint": "eslint . --fix",
44
+ "perf": "node perf/check.js",
45
+ "prepare": "echo 'ready'",
46
+ "prettier": "prettier",
47
+ "prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
48
+ "pretest": "yarn run lect && yarn run build",
49
+ "test": "yarn run devtest",
50
+ "unit": "uvu test"
56
51
  },
57
- "tap": {
58
- "check-coverage": false,
59
- "node-arg": [
60
- "--no-warnings",
61
- "--experimental-loader",
62
- "@istanbuljs/esm-loader-hook"
52
+ "engines": {
53
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
54
+ },
55
+ "c8": {
56
+ "check-coverage": true,
57
+ "exclude": [
58
+ "**/test/**/*.*"
63
59
  ],
64
- "timeout": 0
60
+ "lines": 100
65
61
  },
66
62
  "lect": {
67
63
  "licence": {
68
64
  "extras": [
69
65
  ""
70
66
  ]
71
- },
72
- "req": "{ rIterate }",
73
- "various": {
74
- "devDependencies": [
75
- "ranges-apply",
76
- "ranges-merge"
77
- ]
78
67
  }
79
68
  },
80
- "dependencies": {
81
- "@babel/runtime": "^7.16.3"
82
- },
83
69
  "devDependencies": {
84
- "@babel/cli": "^7.16.0",
85
- "@babel/core": "^7.16.0",
86
- "@babel/node": "^7.16.0",
87
- "@babel/plugin-external-helpers": "^7.16.0",
88
- "@babel/plugin-proposal-class-properties": "^7.16.0",
89
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
90
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
91
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
92
- "@babel/plugin-transform-runtime": "^7.16.4",
93
- "@babel/preset-env": "^7.16.4",
94
- "@babel/preset-typescript": "^7.16.0",
95
- "@babel/register": "^7.16.0",
96
- "@istanbuljs/esm-loader-hook": "^0.1.2",
97
- "@rollup/plugin-babel": "^5.3.0",
98
- "@rollup/plugin-commonjs": "^21.0.1",
99
- "@rollup/plugin-json": "^4.1.0",
100
- "@rollup/plugin-node-resolve": "^13.0.6",
101
- "@rollup/plugin-strip": "^2.1.0",
102
- "@rollup/plugin-typescript": "^8.3.0",
103
- "@types/node": "^16.11.9",
104
- "@types/tap": "^15.0.5",
105
- "@typescript-eslint/eslint-plugin": "^5.4.0",
106
- "@typescript-eslint/parser": "^5.4.0",
107
- "core-js": "^3.19.1",
108
- "cross-env": "^7.0.3",
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",
114
- "rollup-plugin-ascii": "^0.0.3",
115
- "rollup-plugin-banner": "^0.2.1",
116
- "rollup-plugin-cleanup": "^3.2.1",
117
- "rollup-plugin-dts": "^4.0.1",
118
- "rollup-plugin-terser": "^7.0.2",
119
- "tap": "^15.1.2",
120
- "tslib": "^2.3.1",
121
- "typescript": "^4.5.2"
122
- },
123
- "engines": {
124
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
70
+ "ranges-apply": "^6.0.12",
71
+ "ranges-merge": "^8.0.12"
125
72
  }
126
73
  }
package/types/index.d.ts CHANGED
@@ -1,12 +1,19 @@
1
- declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
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
5
 
4
6
  declare const version: string;
5
7
  interface Obj {
6
- i: number;
7
- val: any;
8
+ i: number;
9
+ val: any;
8
10
  }
9
11
  declare type Callback = (obj: Obj) => void;
10
- declare function rIterate(str: string, originalRanges: Ranges, cb: Callback, offset?: number): void;
12
+ declare function rIterate(
13
+ str: string,
14
+ originalRanges: Ranges,
15
+ cb: Callback,
16
+ offset?: number
17
+ ): void;
11
18
 
12
19
  export { rIterate, version };
package/examples/api.json DELETED
@@ -1 +0,0 @@
1
- {"_quickTake.js":{"title":"Quick Take","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; rIterate &#x7D; from \"ranges-iterate\";\n\n// Ranges in the following example \"punches out\" a \"hole\" from `a` to `g`\n// (included), replacing it with `xyz`. That's what gets iterated.\n\nconst gathered = [];\n\n// a callback-based interface:\nrIterate(\"abcdefghij\", [[0, 7, \"xyz\"]], (&#x7B; i, val &#x7D;) => &#x7B;\n gathered.push(`i = $&#x7B;i&#x7D;; val = $&#x7B;val&#x7D;`);\n&#x7D;);\n\nassert.deepEqual(gathered, [\n \"i = 0; val = x\",\n \"i = 1; val = y\",\n \"i = 2; val = z\",\n \"i = 3; val = h\",\n \"i = 4; val = i\",\n \"i = 5; val = j\",\n]);"}}