ranges-process-outside 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-process-outside.esm.js +5 -49
- package/dist/ranges-process-outside.umd.js +27 -22
- package/examples/_quickTake.js +2 -0
- package/package.json +24 -81
- 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 { rProcessOutside } from "ranges-process-outside";
|
|
42
43
|
|
|
43
44
|
const gathered = [];
|
|
@@ -58,7 +59,7 @@ assert.deepEqual(gathered, [0, 5, 6, 7, 8, 9]);
|
|
|
58
59
|
|
|
59
60
|
## Documentation
|
|
60
61
|
|
|
61
|
-
Please [visit codsen.com](https://codsen.com/os/ranges-process-outside/) for a full description of the API
|
|
62
|
+
Please [visit codsen.com](https://codsen.com/os/ranges-process-outside/) for a full description of the API.
|
|
62
63
|
|
|
63
64
|
## Contributing
|
|
64
65
|
|
|
@@ -70,4 +71,6 @@ MIT License
|
|
|
70
71
|
|
|
71
72
|
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
72
73
|
|
|
74
|
+
|
|
73
75
|
<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">
|
|
76
|
+
|
|
@@ -1,57 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-process-outside
|
|
3
3
|
* @fileoverview Iterate string considering ranges, as if they were already applied
|
|
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-process-outside/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import runes from '
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var version$1 = "5.0.4";
|
|
15
|
-
|
|
16
|
-
const version = version$1;
|
|
17
|
-
function rProcessOutside(originalStr, originalRanges, cb, skipChecks = false) {
|
|
18
|
-
if (typeof originalStr !== "string") {
|
|
19
|
-
if (originalStr === undefined) {
|
|
20
|
-
throw new Error(`ranges-process-outside: [THROW_ID_01] the first input argument must be string! It's missing currently (undefined)!`);
|
|
21
|
-
} else {
|
|
22
|
-
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})`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (originalRanges && (!Array.isArray(originalRanges) || originalRanges.length && !Array.isArray(originalRanges[0]))) {
|
|
26
|
-
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})`);
|
|
27
|
-
}
|
|
28
|
-
if (typeof cb !== "function") {
|
|
29
|
-
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})`);
|
|
30
|
-
}
|
|
31
|
-
function iterator(str, arrOfArrays) {
|
|
32
|
-
(arrOfArrays || []).forEach(([fromIdx, toIdx]) => {
|
|
33
|
-
for (let i = fromIdx; i < toIdx; i++) {
|
|
34
|
-
const charLength = runes(str.slice(i))[0].length;
|
|
35
|
-
cb(i, i + charLength, offsetValue => {
|
|
36
|
-
/* istanbul ignore else */
|
|
37
|
-
if (offsetValue != null) {
|
|
38
|
-
i += offsetValue;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
if (charLength && charLength > 1) {
|
|
42
|
-
i += charLength - 1;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
if (originalRanges && originalRanges.length) {
|
|
48
|
-
const temp = rCrop(rInvert(skipChecks ? originalRanges : originalRanges, originalStr.length, {
|
|
49
|
-
skipChecks: !!skipChecks
|
|
50
|
-
}), originalStr.length);
|
|
51
|
-
iterator(originalStr, temp);
|
|
52
|
-
} else {
|
|
53
|
-
iterator(originalStr, [[0, originalStr.length]]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { rProcessOutside, version };
|
|
10
|
+
import m from"runes";import{rInvert as y}from"ranges-invert";import{rCrop as g}from"ranges-crop";var c="5.0.10";var I=c;function v(e,s,r,i=!1){if(typeof e!="string")throw e===void 0?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:
|
|
11
|
+
${JSON.stringify(e,null,4)} (type ${typeof e})`);if(s&&(!Array.isArray(s)||s.length&&!Array.isArray(s[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:
|
|
12
|
+
${JSON.stringify(s,null,4)} (type ${typeof s})`);if(typeof r!="function")throw new Error(`ranges-process-outside: [THROW_ID_04] the third input argument must be a function! It was given as:
|
|
13
|
+
${JSON.stringify(r,null,4)} (type ${typeof r})`);function l(n,p){(p||[]).forEach(([d,a])=>{for(let t=d;t<a;t++){let o=m(n.slice(t))[0].length;r(t,t+o,u=>{u!=null&&(t+=u)}),o&&o>1&&(t+=o-1)}})}if(s?.length){let n=g(y(s,e.length,{skipChecks:!!i}),e.length);l(e,n)}else l(e,[[0,e.length]])}export{v as rProcessOutside,I as version};
|
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ranges-process-outside
|
|
3
3
|
* @fileoverview Iterate string considering ranges, as if they were already applied
|
|
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-process-outside/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* @license MIT
|
|
17
|
-
* {@link https://codsen.com/os/ranges-sort/}
|
|
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)))}
|
|
19
|
-
/**
|
|
20
|
-
* @name ranges-merge
|
|
21
|
-
* @fileoverview Merge and sort string index ranges
|
|
22
|
-
* @version 8.0.4
|
|
23
|
-
* @author Roy Revelt, Codsen Ltd
|
|
24
|
-
* @license MIT
|
|
25
|
-
* {@link https://codsen.com/os/ranges-merge/}
|
|
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}
|
|
10
|
+
var rangesProcessOutside=(()=>{var H=Object.create;var p=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols,k=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var $=(e,r,s)=>r in e?p(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,f=(e,r)=>{for(var s in r||(r={}))w.call(r,s)&&$(e,s,r[s]);if(b)for(var s of b(r))V.call(r,s)&&$(e,s,r[s]);return e};var O=e=>p(e,"__esModule",{value:!0});var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),M=(e,r)=>{for(var s in r)p(e,s,{get:r[s],enumerable:!0})},E=(e,r,s,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of J(r))!w.call(e,o)&&(s||o!=="default")&&p(e,o,{get:()=>r[o],enumerable:!(n=W(r,o))||n.enumerable});return e},G=(e,r)=>E(O(p(e!=null?H(k(e)):{},"default",!r&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),P=(e=>(r,s)=>e&&e.get(r)||(s=E(O({}),r,1),e&&e.set(r,s),s))(typeof WeakMap!="undefined"?new WeakMap:0);var D=j((de,I)=>{"use strict";var R=55296,q=56319,L=56320,Y=127462,B=127487,K=127995,U=127999,Z=65024,z=65039,Q=8400,X=8447,ee=8205,re=[776,2359,2359,2367,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520];function _(e){if(typeof e!="string")throw new Error("string cannot be undefined or null");let r=[],s=0,n=0;for(;s<e.length;){if(n+=te(s+n,e),ae(e[s+n])&&n++,oe(e[s+n])&&n++,ie(e[s+n])&&n++,ue(e[s+n])){n++;continue}r.push(e.substring(s,s+n)),s+=n,n=0}return r}function te(e,r){let s=r[e];if(!ne(s)||e===r.length-1)return 1;let n=s+r[e+1],o=r.substring(e+2,e+5);return x(n)&&x(o)||se(o)?4:2}function ne(e){return e&&y(e[0].charCodeAt(0),R,q)}function x(e){return y(v(e),Y,B)}function se(e){return y(v(e),K,U)}function oe(e){return typeof e=="string"&&y(e.charCodeAt(0),Z,z)}function ie(e){return typeof e=="string"&&y(e.charCodeAt(0),Q,X)}function ae(e){return typeof e=="string"&&re.indexOf(e.charCodeAt(0))!==-1}function ue(e){return typeof e=="string"&&e.charCodeAt(0)===ee}function v(e){let r=e.charCodeAt(0)-R,s=e.charCodeAt(1)-L;return(r<<10)+s+65536}function y(e,r,s){return e>=r&&e<=s}function le(e,r,s){let n=_(e);if(r===void 0)return e;if(r>=n.length)return"";let o=n.length-r,l=r+(s===void 0?o:s);return l>r+o&&(l=void 0),n.slice(r,l).join("")}I.exports=_;I.exports.substr=le});var ye={};M(ye,{rProcessOutside:()=>pe,version:()=>ce});var F=G(D(),1);var fe={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function A(e,r){if(!Array.isArray(e)||!e.length)return e;let s=f(f({},fe),r),n,o;if(s.strictlyTwoElementsInRangeArrays&&!e.every((u,a)=>!Array.isArray(u)||u.length!==2?(n=a,o=u.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((u,a)=>!Array.isArray(u)||!Number.isInteger(u[0])||u[0]<0||!Number.isInteger(u[1])||u[1]<0?(n=a,!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 i=e.length**2,l=0;return Array.from(e).sort((u,a)=>(s.progressFn&&(l+=1,s.progressFn(Math.floor(l*100/i))),u[0]===a[0]?u[1]<a[1]?-1:u[1]>a[1]?1:0:u[0]<a[0]?-1:1))}var N={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function d(e,r){function s(t){return t&&typeof t=="object"&&!Array.isArray(t)}if(!Array.isArray(e)||!e.length)return null;let n;if(r)if(s(r)){if(n=f(f({},N),r),n.progressFn&&s(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&typeof n.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof n.progressFn}", equal to ${JSON.stringify(n.progressFn,null,4)}`);if(![1,2,"1","2"].includes(n.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof n.mergeType}", equal to ${JSON.stringify(n.mergeType,null,4)}`);if(typeof n.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof n.joinRangesThatTouchEdges}", equal to ${JSON.stringify(n.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
|
|
11
|
+
${JSON.stringify(r,null,4)} (type ${typeof r})`);else n=f({},N);let o=e.filter(t=>Array.isArray(t)).map(t=>[...t]).filter(t=>t[2]!==void 0||t[0]!==t[1]),i,l,u;n.progressFn?i=A(o,{progressFn:t=>{u=Math.floor(t/5),u!==l&&(l=u,n.progressFn(u))}}):i=A(o);let a=i.length-1;for(let t=a;t>0;t--)n.progressFn&&(u=Math.floor((1-t/a)*78)+21,u!==l&&u>l&&(l=u,n.progressFn(u))),(i[t][0]<=i[t-1][0]||!n.joinRangesThatTouchEdges&&i[t][0]<i[t-1][1]||n.joinRangesThatTouchEdges&&i[t][0]<=i[t-1][1])&&(i[t-1][0]=Math.min(i[t][0],i[t-1][0]),i[t-1][1]=Math.max(i[t][1],i[t-1][1]),i[t][2]!==void 0&&(i[t-1][0]>=i[t][0]||i[t-1][1]<=i[t][1])&&i[t-1][2]!==null&&(i[t][2]===null&&i[t-1][2]!==null?i[t-1][2]=null:i[t-1][2]!=null?+n.mergeType==2&&i[t-1][0]===i[t][0]?i[t-1][2]=i[t][2]:i[t-1][2]+=i[t][2]:i[t-1][2]=i[t][2]),i.splice(t,1),t=i.length);return i.length?i:null}function m(e,r){if(e===null)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(o=>o).length)return e.filter(o=>o);let s=0;if(!e.filter(o=>o).every((o,i)=>!Number.isInteger(o[0])||!Number.isInteger(o[1])?(s=i,!1):!0))throw Array.isArray(e)&&typeof e[0]=="number"&&typeof e[1]=="number"?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)}!`):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 ${s}th range (${JSON.stringify(e[s],null,0)}) does not consist of only natural numbers!`);if(!e.filter(o=>o).every((o,i)=>o[2]!=null&&typeof o[2]!="string"?(s=i,!1):!0))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 ${s}th range ${JSON.stringify(e[s],null,0)} has a argument in the range of a type ${typeof e[s][2]}`);let n=(d(e)||[]).filter(o=>o[0]<=r&&(o[2]!=null||o[0]<r)).map(o=>o[1]>r?o[2]!=null?[o[0],r,o[2]]:[o[0],r]:o);return n.length?n:null}function S(e,r,s){if(!Array.isArray(e)&&e!==null)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)&&typeof e[0]=="number"&&typeof e[1]=="number")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(a=>Array.isArray(a)&&a[0]!==a[1]).length||!r)return r?[[0,r]]:null;let n=f({strictlyTwoElementsInRangeArrays:!1,skipChecks:!1},s),o=0,i;if(!n.skipChecks&&n.strictlyTwoElementsInRangeArrays&&!e.filter(a=>a).every((a,t)=>a.length!==2?(o=t,i=a.length,!1):!0))throw new TypeError(`ranges-invert: [THROW_ID_04] Because opts.strictlyTwoElementsInRangeArrays was enabled, all ranges must be strictly two-element-long. However, the ${o}th range (${JSON.stringify(e[o],null,0)}) has not two but ${i} elements!`);if(!n.skipChecks&&!e.every((a,t)=>!Number.isInteger(a[0])||a[0]<0||!Number.isInteger(a[1])||a[1]<0?(o=t,!1):!0))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 ${o+1}th range (${JSON.stringify(e[o],null,0)}) does not consist of only natural numbers!`);let l;n.skipChecks?l=e.filter(a=>a[0]!==a[1]):l=d(e.filter(a=>a[0]!==a[1]));let u=l.reduce((a,t,g,c)=>{let T=[];g===0&&c[0][0]!==0&&T.push([0,c[0][0]]);let h=g<c.length-1?c[g+1][0]:r;if(t[1]!==h){if(n.skipChecks&&t[1]>h)throw new TypeError(`ranges-invert: [THROW_ID_08] The checking (opts.skipChecks) is off and input ranges were not sorted! We nearly wrote range [${t[1]}, ${h}] which is backwards. For investigation, whole ranges array is:
|
|
12
|
+
${JSON.stringify(c,null,0)}`);T.push([t[1],h])}return a.concat(T)},[]);return m(u,r)}var C="5.0.10";var ce=C;function pe(e,r,s,n=!1){if(typeof e!="string")throw e===void 0?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:
|
|
13
|
+
${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:
|
|
14
|
+
${JSON.stringify(r,null,4)} (type ${typeof r})`);if(typeof s!="function")throw new Error(`ranges-process-outside: [THROW_ID_04] the third input argument must be a function! It was given as:
|
|
15
|
+
${JSON.stringify(s,null,4)} (type ${typeof s})`);function o(i,l){(l||[]).forEach(([u,a])=>{for(let t=u;t<a;t++){let g=(0,F.default)(i.slice(t))[0].length;s(t,t+g,c=>{c!=null&&(t+=c)}),g&&g>1&&(t+=g-1)}})}if(r==null?void 0:r.length){let i=m(S(r,e.length,{skipChecks:!!n}),e.length);o(e,i)}else o(e,[[0,e.length]])}return P(ye);})();
|
|
27
16
|
/**
|
|
28
17
|
* @name ranges-crop
|
|
29
18
|
* @fileoverview Crop array of ranges when they go beyond the reference string's length
|
|
30
|
-
* @version 5.0.
|
|
19
|
+
* @version 5.0.10
|
|
31
20
|
* @author Roy Revelt, Codsen Ltd
|
|
32
21
|
* @license MIT
|
|
33
22
|
* {@link https://codsen.com/os/ranges-crop/}
|
|
34
|
-
*/
|
|
23
|
+
*/
|
|
35
24
|
/**
|
|
36
25
|
* @name ranges-invert
|
|
37
26
|
* @fileoverview Invert string index ranges
|
|
38
|
-
* @version 5.0.
|
|
27
|
+
* @version 5.0.10
|
|
39
28
|
* @author Roy Revelt, Codsen Ltd
|
|
40
29
|
* @license MIT
|
|
41
30
|
* {@link https://codsen.com/os/ranges-invert/}
|
|
42
|
-
*/
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* @name ranges-merge
|
|
34
|
+
* @fileoverview Merge and sort string index ranges
|
|
35
|
+
* @version 8.0.10
|
|
36
|
+
* @author Roy Revelt, Codsen Ltd
|
|
37
|
+
* @license MIT
|
|
38
|
+
* {@link https://codsen.com/os/ranges-merge/}
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* @name ranges-sort
|
|
42
|
+
* @fileoverview Sort string index ranges
|
|
43
|
+
* @version 5.0.10
|
|
44
|
+
* @author Roy Revelt, Codsen Ltd
|
|
45
|
+
* @license MIT
|
|
46
|
+
* {@link https://codsen.com/os/ranges-sort/}
|
|
47
|
+
*/
|
package/examples/_quickTake.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ranges-process-outside",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.10",
|
|
4
4
|
"description": "Iterate string considering ranges, as if they were already applied",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -28,99 +28,42 @@
|
|
|
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": "{ rProcessOutside }",
|
|
72
|
-
"various": {
|
|
73
|
-
"devDependencies": [
|
|
74
|
-
"@types/runes"
|
|
75
|
-
]
|
|
76
59
|
}
|
|
77
60
|
},
|
|
78
61
|
"dependencies": {
|
|
79
|
-
"
|
|
80
|
-
"ranges-
|
|
81
|
-
"ranges-invert": "^5.0.4",
|
|
62
|
+
"ranges-crop": "^5.0.10",
|
|
63
|
+
"ranges-invert": "^5.0.10",
|
|
82
64
|
"runes": "^0.4.3"
|
|
83
65
|
},
|
|
84
66
|
"devDependencies": {
|
|
85
|
-
"@
|
|
86
|
-
"@babel/core": "^7.16.0",
|
|
87
|
-
"@babel/node": "^7.16.0",
|
|
88
|
-
"@babel/plugin-external-helpers": "^7.16.0",
|
|
89
|
-
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
90
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
91
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
92
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
93
|
-
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
94
|
-
"@babel/preset-env": "^7.16.0",
|
|
95
|
-
"@babel/preset-typescript": "^7.16.0",
|
|
96
|
-
"@babel/register": "^7.16.0",
|
|
97
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
98
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
99
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
100
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
101
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
102
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
103
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
104
|
-
"@types/node": "^16.11.6",
|
|
105
|
-
"@types/runes": "^0.4.1",
|
|
106
|
-
"@types/tap": "^15.0.5",
|
|
107
|
-
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
|
108
|
-
"@typescript-eslint/parser": "^5.3.0",
|
|
109
|
-
"core-js": "^3.19.1",
|
|
110
|
-
"cross-env": "^7.0.3",
|
|
111
|
-
"eslint": "^8.1.0",
|
|
112
|
-
"lect": "^0.18.4",
|
|
113
|
-
"rollup": "^2.59.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.0",
|
|
118
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
119
|
-
"tap": "^15.0.10",
|
|
120
|
-
"tslib": "^2.3.1",
|
|
121
|
-
"typescript": "^4.4.4"
|
|
122
|
-
},
|
|
123
|
-
"engines": {
|
|
124
|
-
"node": ">=12"
|
|
67
|
+
"@types/runes": "^0.4.1"
|
|
125
68
|
}
|
|
126
69
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
declare type Ranges = Range[] | null;
|
|
1
|
+
import { Ranges } from 'ranges-crop';
|
|
3
2
|
|
|
4
3
|
declare const version: string;
|
|
5
|
-
|
|
6
4
|
declare type OffsetValueCb = (amountToOffset: number) => void;
|
|
7
5
|
declare type Callback = (fromIdx: number, toIdx: number, offsetValueCb: OffsetValueCb) => void;
|
|
8
6
|
declare function rProcessOutside(originalStr: string, originalRanges: Ranges, cb: Callback, skipChecks?: boolean): void;
|
package/examples/api.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { rProcessOutside } from \"ranges-process-outside\";\n\nconst gathered = [];\n\n// a callback interface:\nrProcessOutside(\n \"abcdefghij\",\n [\n [1, 5], // delete from \"b\" to \"f\"\n ],\n (fromIdx, toIdx, offsetValueCb) => {\n gathered.push(fromIdx);\n }\n);\n\nassert.deepEqual(gathered, [0, 5, 6, 7, 8, 9]);"}}
|