ranges-process-outside 5.0.7 → 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/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 and examples.
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,61 +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.7
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 'runes';
11
- import { rInvert } from 'ranges-invert';
12
- import { rCrop } from 'ranges-crop';
13
-
14
- var version$1 = "5.0.7";
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
- }
22
- else {
23
- 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})`);
24
- }
25
- }
26
- if (originalRanges &&
27
- (!Array.isArray(originalRanges) ||
28
- (originalRanges.length && !Array.isArray(originalRanges[0])))) {
29
- 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})`);
30
- }
31
- if (typeof cb !== "function") {
32
- 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})`);
33
- }
34
- function iterator(str, arrOfArrays) {
35
- (arrOfArrays || []).forEach(([fromIdx, toIdx]) => {
36
- for (let i = fromIdx; i < toIdx; i++) {
37
- const charLength = runes(str.slice(i))[0].length;
38
- cb(i, i + charLength, (offsetValue) => {
39
- /* istanbul ignore else */
40
- if (offsetValue != null) {
41
- i += offsetValue;
42
- }
43
- });
44
- if (charLength && charLength > 1) {
45
- i += charLength - 1;
46
- }
47
- }
48
- });
49
- }
50
- if (originalRanges && originalRanges.length) {
51
- const temp = rCrop(rInvert(skipChecks ? originalRanges : originalRanges, originalStr.length, {
52
- skipChecks: !!skipChecks,
53
- }), originalStr.length);
54
- iterator(originalStr, temp);
55
- }
56
- else {
57
- iterator(originalStr, [[0, originalStr.length]]);
58
- }
59
- }
60
-
61
- 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.7
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
- !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
- /**
12
- * @name ranges-sort
13
- * @fileoverview Sort string index ranges
14
- * @version 5.0.7
15
- * @author Roy Revelt, Codsen Ltd
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.7
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.7
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
- */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}
23
+ */
35
24
  /**
36
25
  * @name ranges-invert
37
26
  * @fileoverview Invert string index ranges
38
- * @version 5.0.7
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
- */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.7",Object.defineProperty(e,"__esModule",{value:!0})}));
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
+ */
@@ -1,6 +1,8 @@
1
+ /* eslint-disable no-unused-vars */
1
2
  // Quick Take
2
3
 
3
4
  import { strict as assert } from "assert";
5
+
4
6
  import { rProcessOutside } from "../dist/ranges-process-outside.esm.js";
5
7
 
6
8
  const gathered = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ranges-process-outside",
3
- "version": "5.0.7",
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,95 +28,42 @@
28
28
  },
29
29
  "types": "types/index.d.ts",
30
30
  "scripts": {
31
- "build": "rollup -c",
32
- "build:esbuild": "node '../../scripts/esbuild.js'",
33
- "build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
34
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
35
- "clean_types": "../../scripts/cleanTypes.js",
36
- "dev": "rollup -c --dev",
37
- "devunittest": "npm run dev && tap --only -R 'base'",
38
- "format": "npm run lect && npm run prettier && npm run lint",
39
- "lect": "lect",
40
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
41
- "perf": "node perf/check",
42
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
43
- "republish": "npm publish || :",
44
- "tap": "tap",
45
- "pretest": "npm run build",
46
- "test": "npm run test:ci && npm run perf",
47
- "test:ci": "npm run unittest && npm run test:examples && npm run format",
48
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
49
- "tsc": "tsc",
50
- "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
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
- "tap": {
53
- "check-coverage": false,
54
- "node-arg": [
55
- "--no-warnings",
56
- "--experimental-loader",
57
- "@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/**/*.*"
58
51
  ],
59
- "timeout": 0
52
+ "lines": 100
60
53
  },
61
54
  "lect": {
62
55
  "licence": {
63
56
  "extras": [
64
57
  ""
65
58
  ]
66
- },
67
- "req": "{ rProcessOutside }",
68
- "various": {
69
- "devDependencies": [
70
- "@types/runes"
71
- ]
72
59
  }
73
60
  },
74
61
  "dependencies": {
75
- "@babel/runtime": "^7.16.3",
76
- "ranges-crop": "^5.0.7",
77
- "ranges-invert": "^5.0.7",
62
+ "ranges-crop": "^5.0.10",
63
+ "ranges-invert": "^5.0.10",
78
64
  "runes": "^0.4.3"
79
65
  },
80
66
  "devDependencies": {
81
- "@babel/cli": "^7.16.0",
82
- "@babel/core": "^7.16.0",
83
- "@babel/node": "^7.16.0",
84
- "@babel/plugin-external-helpers": "^7.16.0",
85
- "@babel/plugin-proposal-class-properties": "^7.16.0",
86
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
87
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
88
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
89
- "@babel/plugin-transform-runtime": "^7.16.4",
90
- "@babel/preset-env": "^7.16.4",
91
- "@babel/preset-typescript": "^7.16.0",
92
- "@babel/register": "^7.16.0",
93
- "@istanbuljs/esm-loader-hook": "^0.1.2",
94
- "@rollup/plugin-babel": "^5.3.0",
95
- "@rollup/plugin-commonjs": "^21.0.1",
96
- "@rollup/plugin-json": "^4.1.0",
97
- "@rollup/plugin-node-resolve": "^13.0.6",
98
- "@rollup/plugin-strip": "^2.1.0",
99
- "@rollup/plugin-typescript": "^8.3.0",
100
- "@types/node": "^16.11.10",
101
- "@types/runes": "^0.4.1",
102
- "@types/tap": "^15.0.5",
103
- "@typescript-eslint/eslint-plugin": "^5.5.0",
104
- "@typescript-eslint/parser": "^5.5.0",
105
- "core-js": "^3.19.2",
106
- "cross-env": "^7.0.3",
107
- "eslint": "^8.3.0",
108
- "lect": "^0.18.7",
109
- "rollup": "^2.60.1",
110
- "rollup-plugin-ascii": "^0.0.3",
111
- "rollup-plugin-banner": "^0.2.1",
112
- "rollup-plugin-cleanup": "^3.2.1",
113
- "rollup-plugin-dts": "^4.0.1",
114
- "rollup-plugin-terser": "^7.0.2",
115
- "tap": "^15.1.5",
116
- "tslib": "^2.3.1",
117
- "typescript": "^4.5.2"
118
- },
119
- "engines": {
120
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
67
+ "@types/runes": "^0.4.1"
121
68
  }
122
69
  }
package/types/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
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 &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; rProcessOutside &#x7D; 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) => &#x7B;\n gathered.push(fromIdx);\n &#x7D;\n);\n\nassert.deepEqual(gathered, [0, 5, 6, 7, 8, 9]);"}}