ranges-push
Advanced tools
Comparing version 6.2.2 to 6.2.3
@@ -115,34 +115,34 @@ # Change Log | ||
- ✨ Various documentation and setup tweaks after we migrated to monorepo | ||
- ✨ Setup refresh: updated dependencies and all config files using automated tools | ||
- Various documentation and setup tweaks after we migrated to monorepo | ||
- Setup refresh: updated dependencies and all config files using automated tools | ||
## 2.13.0 (2018-12-26) | ||
- ✨ Harden the type checks just in case ([106ae7a](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/commits/106ae7a)) | ||
- ✨ Implement throw pinning in unit tests ([6b8c789](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/commits/6b8c789)) | ||
- ✨ Omit the 3rd argument when it's equal to an empty string ([343c153](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/commits/343c153)) | ||
- ✨ Add `opts.limitLinebreaksCount` ([55eedfa](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/commits/55eedfa)) | ||
- Harden the type checks just in case ([106ae7a](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/commits/106ae7a)) | ||
- Implement throw pinning in unit tests ([6b8c789](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/commits/6b8c789)) | ||
- Omit the 3rd argument when it's equal to an empty string ([343c153](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/commits/343c153)) | ||
- Add `opts.limitLinebreaksCount` ([55eedfa](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/commits/55eedfa)) | ||
## 2.12.0 (2018-10-25) | ||
- ✨ Updated all dependencies | ||
- ✨ Restored coveralls.io reporting | ||
- ✨ Restored unit test linting | ||
- Updated all dependencies | ||
- Restored coveralls.io reporting | ||
- Restored unit test linting | ||
## 2.11.0 (2018-07-26) | ||
- ✨ If third argument is an empty string, now it's being completely omited. This is necessary for unit tests' sanity. Otherwise, it's impossible to `deepEqual`-match. | ||
- If third argument is an empty string, now it's being completely omited. This is necessary for unit tests' sanity. Otherwise, it's impossible to `deepEqual`-match. | ||
## 2.10.0 (2018-07-03) | ||
- ✨ Added `opts.limitLinebreaksCount` - this will allow double linebreaks resulting in an empty row between the content lines. | ||
- Added `opts.limitLinebreaksCount` - this will allow double linebreaks resulting in an empty row between the content lines. | ||
## 2.9.0 (2018-06-18) | ||
- ✨ Rename to `ranges-push` and migrate to Bitbucket | ||
- Rename to `ranges-push` and migrate to Bitbucket | ||
## 2.8.0 (2018-05-19) | ||
- ✨ Fixed second input argument throw error message reporting. Previously, when second argument was of a wrong type, the first argument's details were reported which caused confusion. Fixed now. | ||
- ✨ Throw error pinning in unit tests. Otherwise we would not be able to prove this feature above is correctly implemented. Both before and after were throwing an error. The correctness is distinguished by _which_ error exactly, (first arg's wrong type) `THROW_ID_09` or (newly added second arg's wrong type) `THROW_ID_10`. I'd go as far as to say, if _throw pinning_ was implemented at the beginning, this bug would not have happened. | ||
- Fixed second input argument throw error message reporting. Previously, when second argument was of a wrong type, the first argument's details were reported which caused confusion. Fixed now. | ||
- Throw error pinning in unit tests. Otherwise we would not be able to prove this feature above is correctly implemented. Both before and after were throwing an error. The correctness is distinguished by _which_ error exactly, (first arg's wrong type) `THROW_ID_09` or (newly added second arg's wrong type) `THROW_ID_10`. I'd go as far as to say, if _throw pinning_ was implemented at the beginning, this bug would not have happened. | ||
@@ -153,14 +153,14 @@ ## 2.7.0 (2018-05-11) | ||
- ✨ Set up [Prettier](https://prettier.io) | ||
- ✨ Removed `package.lock` and `.editorconfig` | ||
- ✨ Wired Rollup to remove comments from non-dev builds. This means we can now leave the `console.log`s in the source code — Rollup will remove them from production code. | ||
- ✨ Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed | ||
- Set up [Prettier](https://prettier.io) | ||
- Removed `package.lock` and `.editorconfig` | ||
- Wired Rollup to remove comments from non-dev builds. This means we can now leave the `console.log`s in the source code — Rollup will remove them from production code. | ||
- Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed | ||
## 2.6.0 (2018-02-24) | ||
- ✨ Chillax™ feature. If `null` is being `.push`ed, nothing happens. It won't `throw` from now on. | ||
- Chillax™ feature. If `null` is being `.push`ed, nothing happens. It won't `throw` from now on. | ||
## 2.5.0 (2018-02-10) | ||
- ✨ Now accepts output of another slices class (its `.current()` output) as the first input argument. Now, it won't throw an error that second argument is missing, provided the validation of the array from the 1st argument passes. | ||
- Now accepts output of another slices class (its `.current()` output) as the first input argument. Now, it won't throw an error that second argument is missing, provided the validation of the array from the 1st argument passes. | ||
@@ -173,3 +173,3 @@ In practice, I'm going to use it in [string-remove-duplicate-heads-tails](https://www.npmjs.com/package/string-remove-duplicate-heads-tails) for example, where I there will be two-step process. Range comes in as a plausible range, then we traverse further and if further ranges are found, that plausible-one is merged into the real ranges slices array class. This merging up until now was a problem - it could only be done iterating one array and `.push`ing each range one-by-one into another slices array. | ||
- ✨ `opts.limitToBeAddedWhitespace` now also collapses the leading and trailing whitespace. If any chunk of leading whitespace (anything that would get `trim()`'med) contain line break `\n`, it's turned into `\n`. Otherwise, it's turned into single space. | ||
- `opts.limitToBeAddedWhitespace` now also collapses the leading and trailing whitespace. If any chunk of leading whitespace (anything that would get `trim()`'med) contain line break `\n`, it's turned into `\n`. Otherwise, it's turned into single space. | ||
@@ -187,11 +187,11 @@ ```js | ||
- ✨ `.push` as an alias for `.add`. Both do the same thing. I thought the name of this package has "push" so why there is no such method? Until now, that is. | ||
- `.push` as an alias for `.add`. Both do the same thing. I thought the name of this package has "push" so why there is no such method? Until now, that is. | ||
## 2.2.0 (2017-12-29) | ||
- ✨ When third argument is `null`, any merged range results will have there `null`. | ||
- When third argument is `null`, any merged range results will have there `null`. | ||
## 2.1.0 (2017-12-20) | ||
- ✨ `opts.limitToBeAddedWhitespace` - makes life easier when cleaning HTML. Now, chunk ranges can contain any amount of whitespace - the `current()` will run `string-collapse` on the to-be-inserted, third argument. Now, if there are any line breaks among the whitespace characters, the result will be a single line break instead. Basically, when this setting is active, only space or linebreak will be inserted in place of deleted range. | ||
- `opts.limitToBeAddedWhitespace` - makes life easier when cleaning HTML. Now, chunk ranges can contain any amount of whitespace - the `current()` will run `string-collapse` on the to-be-inserted, third argument. Now, if there are any line breaks among the whitespace characters, the result will be a single line break instead. Basically, when this setting is active, only space or linebreak will be inserted in place of deleted range. | ||
@@ -202,5 +202,5 @@ What this feature gives you is you can activate it and freely push chunks of string in, extracting whitespace along it and pushing it too. You don't need to care about excessive amount of it - this library will truncate it automatically. It's very handy when stripping strings from [HTML tags](https://www.npmjs.com/package/string-strip-html) for example. | ||
- ✨ Rewrite in ES modules | ||
- ✨ Now serving three builds: CommonJS, UMD and ES modules, all wired up to appropriate end-points on `package.json` | ||
- ✨ If you have two ranges where second-one completely overlaps the first-one and the first has third argument, something to insert in its place, that third argument will be discarded upon merge. | ||
- Rewrite in ES modules | ||
- Now serving three builds: CommonJS, UMD and ES modules, all wired up to appropriate end-points on `package.json` | ||
- If you have two ranges where second-one completely overlaps the first-one and the first has third argument, something to insert in its place, that third argument will be discarded upon merge. | ||
@@ -220,16 +220,16 @@ Let's say you got these two ranges: | ||
- ✨ Actually serving the transpiled version as default. Sorry about that. Now the transpiled source is wired to `package.json` `main`. The proper Rollup setup (UMD, ESJ and ESM builds) is in coming next. | ||
- Actually serving the transpiled version as default. Sorry about that. Now the transpiled source is wired to `package.json` `main`. The proper Rollup setup (UMD, ESJ and ESM builds) is in coming next. | ||
## 1.5.0 (2017-09-18) | ||
- ✨ Separated the merging function into a separate library, [ranges-merge](https://www.npmjs.com/package/ranges-merge). | ||
- Separated the merging function into a separate library, [ranges-merge](https://www.npmjs.com/package/ranges-merge). | ||
## 1.4.0 (2017-09-12) | ||
- ✨ Separated ranges sorting function into a [separate library](https://www.npmjs.com/package/ranges-sort) because it will be needed in [Detergent](https://www.npmjs.com/package/detergent). | ||
- ✨ Replaced JS Standard with ESLint on `airbnb-base` config with two exceptions: 1. no semicolons and 2. allow plus-plus in `for`-loops. For posterity JS Standard has been neglected by its maintainers, currently it's using half-year old version of ESLint, and doesn't tap to majority of its rules. After activating ESLint, it found some style issues that needed fixing. I like that. | ||
- Separated ranges sorting function into a [separate library](https://www.npmjs.com/package/ranges-sort) because it will be needed in [Detergent](https://www.npmjs.com/package/detergent). | ||
- Replaced JS Standard with ESLint on `airbnb-base` config with two exceptions: 1. no semicolons and 2. allow plus-plus in `for`-loops. For posterity JS Standard has been neglected by its maintainers, currently it's using half-year old version of ESLint, and doesn't tap to majority of its rules. After activating ESLint, it found some style issues that needed fixing. I like that. | ||
## 1.3.0 (2017-08-30) | ||
- ✨ Transpiled version is available from the folder `/es5/`. | ||
- Transpiled version is available from the folder `/es5/`. | ||
@@ -242,6 +242,6 @@ ## 1.2.0 (2017-08-16) | ||
- ✨ An improvement to the algorithm which doesn't change API: sorting and merging is now done upon querying `.current()`, not during `.add()`. This guarantees maximum data precision, especially if you don't do any `.add()` after calling `.current()` and processing the slices array using [string-replace-slices-array](https://www.npmjs.com/package/ranges-apply). | ||
- An improvement to the algorithm which doesn't change API: sorting and merging is now done upon querying `.current()`, not during `.add()`. This guarantees maximum data precision, especially if you don't do any `.add()` after calling `.current()` and processing the slices array using [string-replace-slices-array](https://www.npmjs.com/package/ranges-apply). | ||
## 1.0.0 (2017-07-28) | ||
- ✨ First public release | ||
- First public release |
/** | ||
* @name ranges-push | ||
* @fileoverview Gather string index ranges | ||
* @version 6.2.2 | ||
* @version 6.2.3 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -10,3 +10,3 @@ * @license MIT | ||
import{collWhitespace as y}from"string-collapse-leading-whitespace";var b={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function h(a,r){if(!Array.isArray(a)||!a.length)return a;let t={...b,...r},e,l;if(t.strictlyTwoElementsInRangeArrays&&!a.every((o,g)=>!Array.isArray(o)||o.length!==2?(e=g,l=o.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, ${e}th range (${JSON.stringify(a[e],null,4)}) has not two but ${l} elements!`);if(!a.every((o,g)=>!Array.isArray(o)||!Number.isInteger(o[0])||o[0]<0||!Number.isInteger(o[1])||o[1]<0?(e=g,!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, ${e}th range (${JSON.stringify(a[e],null,4)}) does not consist of only natural numbers!`);let n=a.length**2,i=0;return Array.from(a).sort((o,g)=>(t.progressFn&&(i+=1,t.progressFn(Math.floor(i*100/n))),o[0]===g[0]?o[1]<g[1]?-1:o[1]>g[1]?1:0:o[0]<g[0]?-1:1))}var d="6.2.2";var c={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function f(a,r){function t(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}if(!Array.isArray(a)||!a.length)return null;let e;if(r)if(t(r)){if(e={...c,...r},e.progressFn&&t(e.progressFn)&&!Object.keys(e.progressFn).length)e.progressFn=null;else if(e.progressFn&&typeof e.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] resolvedOpts.progressFn must be a function! It was given of a type: "${typeof e.progressFn}", equal to ${JSON.stringify(e.progressFn,null,4)}`);if(![1,2,"1","2"].includes(e.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] resolvedOpts.mergeType was customised to a wrong thing! It was given of a type: "${typeof e.mergeType}", equal to ${JSON.stringify(e.mergeType,null,4)}`);if(typeof e.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] resolvedOpts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof e.joinRangesThatTouchEdges}", equal to ${JSON.stringify(e.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as: | ||
import{collWhitespace as y}from"string-collapse-leading-whitespace";var b={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function h(a,r){if(!Array.isArray(a)||!a.length)return a;let t={...b,...r},e,l;if(t.strictlyTwoElementsInRangeArrays&&!a.every((o,g)=>!Array.isArray(o)||o.length!==2?(e=g,l=o.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, ${e}th range (${JSON.stringify(a[e],null,4)}) has not two but ${l} elements!`);if(!a.every((o,g)=>!Array.isArray(o)||!Number.isInteger(o[0])||o[0]<0||!Number.isInteger(o[1])||o[1]<0?(e=g,!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, ${e}th range (${JSON.stringify(a[e],null,4)}) does not consist of only natural numbers!`);let n=a.length**2,i=0;return Array.from(a).sort((o,g)=>(t.progressFn&&(i+=1,t.progressFn(Math.floor(i*100/n))),o[0]===g[0]?o[1]<g[1]?-1:o[1]>g[1]?1:0:o[0]<g[0]?-1:1))}var d="6.2.3";var c={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function f(a,r){function t(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}if(!Array.isArray(a)||!a.length)return null;let e;if(r)if(t(r)){if(e={...c,...r},e.progressFn&&t(e.progressFn)&&!Object.keys(e.progressFn).length)e.progressFn=null;else if(e.progressFn&&typeof e.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] resolvedOpts.progressFn must be a function! It was given of a type: "${typeof e.progressFn}", equal to ${JSON.stringify(e.progressFn,null,4)}`);if(![1,2,"1","2"].includes(e.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] resolvedOpts.mergeType was customised to a wrong thing! It was given of a type: "${typeof e.mergeType}", equal to ${JSON.stringify(e.mergeType,null,4)}`);if(typeof e.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] resolvedOpts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof e.joinRangesThatTouchEdges}", equal to ${JSON.stringify(e.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as: | ||
${JSON.stringify(r,null,4)} (type ${typeof r})`);else e={...c};let l=a.filter(s=>Array.isArray(s)).map(s=>[...s]).filter(s=>s[2]!==void 0||s[0]!==s[1]),n,i,o;e.progressFn?n=h(l,{progressFn:s=>{o=Math.floor(s/5),o!==i&&(i=o,e.progressFn(o))}}):n=h(l);let g=n.length-1;for(let s=g;s>0;s--)e.progressFn&&(o=Math.floor((1-s/g)*78)+21,o!==i&&o>i&&(i=o,e.progressFn(o))),(n[s][0]<=n[s-1][0]||!e.joinRangesThatTouchEdges&&n[s][0]<n[s-1][1]||e.joinRangesThatTouchEdges&&n[s][0]<=n[s-1][1])&&(n[s-1][0]=Math.min(n[s][0],n[s-1][0]),n[s-1][1]=Math.max(n[s][1],n[s-1][1]),n[s][2]!==void 0&&(n[s-1][0]>=n[s][0]||n[s-1][1]<=n[s][1])&&n[s-1][2]!==null&&(n[s][2]===null&&n[s-1][2]!==null?n[s-1][2]=null:n[s-1][2]!=null?+e.mergeType==2&&n[s-1][0]===n[s][0]?n[s-1][2]=n[s][2]:n[s-1][2]+=n[s][2]:n[s-1][2]=n[s][2]),n.splice(s,1),s=n.length);return n.length?n:null}var I=d;function u(a){return a!=null}function p(a){return Number.isInteger(a)&&a>=0}function m(a){return typeof a=="string"}var T={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},$=class{constructor(r){let t={...T,...r};if(t.mergeType&&t.mergeType!==1&&t.mergeType!==2)if(m(t.mergeType)&&t.mergeType.trim()==="1")t.mergeType=1;else if(m(t.mergeType)&&t.mergeType.trim()==="2")t.mergeType=2;else throw new Error(`ranges-push: [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)}`);this.opts=t,this.ranges=[]}ranges;opts;add(r,t,e){if(r==null&&t==null)return;if(u(r)&&!u(t)){if(Array.isArray(r)){if(r.length){if(r.some(i=>Array.isArray(i))){r.forEach(i=>{Array.isArray(i)&&this.add(...i)});return}r.length&&p(+r[0])&&p(+r[1])&&this.add(...r)}return}throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(r,null,0)}) but second-one, "to" is not (${JSON.stringify(t,null,0)})`)}else if(!u(r)&&u(t))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(t,null,0)}) but first-one, "from" is not (${JSON.stringify(r,null,0)})`);let l=+r,n=+t;if(p(e)&&(e=String(e)),p(l)&&p(n)){if(u(e)&&!m(e)&&!p(e))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof e}, equal to: | ||
@@ -17,3 +17,3 @@ ${JSON.stringify(e,null,4)}`);if(u(this.ranges)&&Array.isArray(this.last())&&l===this.last()[1]){if(this.last()[1]=n,this.last()[2],this.last()[2]!==null&&u(e)){let i=this.last()[2]&&this.last()[2].length&&(!this.opts?.mergeType||this.opts.mergeType===1)?`${this.last()[2]}${e}`:e;this.opts.limitToBeAddedWhitespace&&(i=y(i,this.opts.limitLinebreaksCount)),m(i)&&!i.length||(this.last()[2]=i)}}else{this.ranges||(this.ranges=[]);let i=e!==void 0&&!(m(e)&&!e.length)?[l,n,e&&this.opts.limitToBeAddedWhitespace?y(e,this.opts.limitLinebreaksCount):e]:[l,n];this.ranges.push(i)}}else throw p(l)&&l>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof n}" equal to: ${JSON.stringify(n,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof l}" equal to: ${JSON.stringify(l,null,4)}`)}push(r,t,e){this.add(r,t,e)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=f(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(r=>u(r[2])?[r[0],r[1],y(r[2],this.opts.limitLinebreaksCount)]:r):this.ranges):null}wipe(){this.ranges=[]}replace(r){if(Array.isArray(r)&&r.length)if(Array.isArray(r[0])&&p(r[0][0]))this.ranges=Array.from(r);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(r[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};export{$ as Ranges,T as defaults,I as version}; | ||
* @fileoverview Sort string index ranges | ||
* @version 5.1.1 | ||
* @version 5.1.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -20,0 +20,0 @@ * @license MIT |
/** | ||
* @name ranges-push | ||
* @fileoverview Gather string index ranges | ||
* @version 6.2.2 | ||
* @version 6.2.3 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -13,3 +13,3 @@ * @license MIT | ||
`;if(!e)return e;let O=0,y=0,c="";for(let u=0,v=e.length;u<v;u++)(e[u]===a||e[u]===t&&e[u-1]!==a)&&y++,`\r | ||
`.includes(e[u])||e[u]===o?(O=0,e[u]===o?c+=e[u]:e[u]===a?y<=g&&(c+=e[u],e[u+1]===t&&(c+=e[u+1],u++)):e[u]===t&&(e==null?void 0:e[u-1])!==a&&y<=g&&(c+=e[u])):(O++,!e[u+1]&&!y&&(c+=" "));return c}if(typeof r=="string"&&r.length){let e=1;typeof+n=="number"&&Number.isInteger(+n)&&+n>=0&&(e=+n);let g="",i="";if(!r.trim())g=r;else if(!r[0].trim()){for(let a=0,t=r.length;a<t;a++)if(r[a].trim()){g=r.slice(0,a);break}}if(r.trim()&&(r.slice(-1).trim()===""||r.slice(-1)===o)){for(let a=r.length;a--;)if(r[a].trim()){i=r.slice(a+1);break}}return`${l(g,e,!1)}${r.trim()}${s(l(s(i),e,!0))}`}return r}var F={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function T(r,n){if(!Array.isArray(r)||!r.length)return r;let o=p(p({},F),n),s,l;if(o.strictlyTwoElementsInRangeArrays&&!r.every((i,a)=>!Array.isArray(i)||i.length!==2?(s=a,l=i.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, ${s}th range (${JSON.stringify(r[s],null,4)}) has not two but ${l} elements!`);if(!r.every((i,a)=>!Array.isArray(i)||!Number.isInteger(i[0])||i[0]<0||!Number.isInteger(i[1])||i[1]<0?(s=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, ${s}th range (${JSON.stringify(r[s],null,4)}) does not consist of only natural numbers!`);let e=r.length**2,g=0;return Array.from(r).sort((i,a)=>(o.progressFn&&(g+=1,o.progressFn(Math.floor(g*100/e))),i[0]===a[0]?i[1]<a[1]?-1:i[1]>a[1]?1:0:i[0]<a[0]?-1:1))}var A="6.2.2";var N={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function S(r,n){function o(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}if(!Array.isArray(r)||!r.length)return null;let s;if(n)if(o(n)){if(s=p(p({},N),n),s.progressFn&&o(s.progressFn)&&!Object.keys(s.progressFn).length)s.progressFn=null;else if(s.progressFn&&typeof s.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] resolvedOpts.progressFn must be a function! It was given of a type: "${typeof s.progressFn}", equal to ${JSON.stringify(s.progressFn,null,4)}`);if(![1,2,"1","2"].includes(s.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] resolvedOpts.mergeType was customised to a wrong thing! It was given of a type: "${typeof s.mergeType}", equal to ${JSON.stringify(s.mergeType,null,4)}`);if(typeof s.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] resolvedOpts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof s.joinRangesThatTouchEdges}", equal to ${JSON.stringify(s.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as: | ||
`.includes(e[u])||e[u]===o?(O=0,e[u]===o?c+=e[u]:e[u]===a?y<=g&&(c+=e[u],e[u+1]===t&&(c+=e[u+1],u++)):e[u]===t&&(e==null?void 0:e[u-1])!==a&&y<=g&&(c+=e[u])):(O++,!e[u+1]&&!y&&(c+=" "));return c}if(typeof r=="string"&&r.length){let e=1;typeof+n=="number"&&Number.isInteger(+n)&&+n>=0&&(e=+n);let g="",i="";if(!r.trim())g=r;else if(!r[0].trim()){for(let a=0,t=r.length;a<t;a++)if(r[a].trim()){g=r.slice(0,a);break}}if(r.trim()&&(r.slice(-1).trim()===""||r.slice(-1)===o)){for(let a=r.length;a--;)if(r[a].trim()){i=r.slice(a+1);break}}return`${l(g,e,!1)}${r.trim()}${s(l(s(i),e,!0))}`}return r}var F={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function T(r,n){if(!Array.isArray(r)||!r.length)return r;let o=p(p({},F),n),s,l;if(o.strictlyTwoElementsInRangeArrays&&!r.every((i,a)=>!Array.isArray(i)||i.length!==2?(s=a,l=i.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, ${s}th range (${JSON.stringify(r[s],null,4)}) has not two but ${l} elements!`);if(!r.every((i,a)=>!Array.isArray(i)||!Number.isInteger(i[0])||i[0]<0||!Number.isInteger(i[1])||i[1]<0?(s=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, ${s}th range (${JSON.stringify(r[s],null,4)}) does not consist of only natural numbers!`);let e=r.length**2,g=0;return Array.from(r).sort((i,a)=>(o.progressFn&&(g+=1,o.progressFn(Math.floor(g*100/e))),i[0]===a[0]?i[1]<a[1]?-1:i[1]>a[1]?1:0:i[0]<a[0]?-1:1))}var A="6.2.3";var N={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function S(r,n){function o(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}if(!Array.isArray(r)||!r.length)return null;let s;if(n)if(o(n)){if(s=p(p({},N),n),s.progressFn&&o(s.progressFn)&&!Object.keys(s.progressFn).length)s.progressFn=null;else if(s.progressFn&&typeof s.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] resolvedOpts.progressFn must be a function! It was given of a type: "${typeof s.progressFn}", equal to ${JSON.stringify(s.progressFn,null,4)}`);if(![1,2,"1","2"].includes(s.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] resolvedOpts.mergeType was customised to a wrong thing! It was given of a type: "${typeof s.mergeType}", equal to ${JSON.stringify(s.mergeType,null,4)}`);if(typeof s.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] resolvedOpts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof s.joinRangesThatTouchEdges}", equal to ${JSON.stringify(s.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as: | ||
${JSON.stringify(n,null,4)} (type ${typeof n})`);else s=p({},N);let l=r.filter(t=>Array.isArray(t)).map(t=>[...t]).filter(t=>t[2]!==void 0||t[0]!==t[1]),e,g,i;s.progressFn?e=T(l,{progressFn:t=>{i=Math.floor(t/5),i!==g&&(g=i,s.progressFn(i))}}):e=T(l);let a=e.length-1;for(let t=a;t>0;t--)s.progressFn&&(i=Math.floor((1-t/a)*78)+21,i!==g&&i>g&&(g=i,s.progressFn(i))),(e[t][0]<=e[t-1][0]||!s.joinRangesThatTouchEdges&&e[t][0]<e[t-1][1]||s.joinRangesThatTouchEdges&&e[t][0]<=e[t-1][1])&&(e[t-1][0]=Math.min(e[t][0],e[t-1][0]),e[t-1][1]=Math.max(e[t][1],e[t-1][1]),e[t][2]!==void 0&&(e[t-1][0]>=e[t][0]||e[t-1][1]<=e[t][1])&&e[t-1][2]!==null&&(e[t][2]===null&&e[t-1][2]!==null?e[t-1][2]=null:e[t-1][2]!=null?+s.mergeType==2&&e[t-1][0]===e[t][0]?e[t-1][2]=e[t][2]:e[t-1][2]+=e[t][2]:e[t-1][2]=e[t][2]),e.splice(t,1),t=e.length);return e.length?e:null}var H=A;function m(r){return r!=null}function h(r){return Number.isInteger(r)&&r>=0}function f(r){return typeof r=="string"}var V={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},E=class{constructor(n){R(this,"ranges");R(this,"opts");let o=p(p({},V),n);if(o.mergeType&&o.mergeType!==1&&o.mergeType!==2)if(f(o.mergeType)&&o.mergeType.trim()==="1")o.mergeType=1;else if(f(o.mergeType)&&o.mergeType.trim()==="2")o.mergeType=2;else throw new Error(`ranges-push: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof o.mergeType}", equal to ${JSON.stringify(o.mergeType,null,4)}`);this.opts=o,this.ranges=[]}add(n,o,s){var g;if(n==null&&o==null)return;if(m(n)&&!m(o)){if(Array.isArray(n)){if(n.length){if(n.some(i=>Array.isArray(i))){n.forEach(i=>{Array.isArray(i)&&this.add(...i)});return}n.length&&h(+n[0])&&h(+n[1])&&this.add(...n)}return}throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(n,null,0)}) but second-one, "to" is not (${JSON.stringify(o,null,0)})`)}else if(!m(n)&&m(o))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(o,null,0)}) but first-one, "from" is not (${JSON.stringify(n,null,0)})`);let l=+n,e=+o;if(h(s)&&(s=String(s)),h(l)&&h(e)){if(m(s)&&!f(s)&&!h(s))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof s}, equal to: | ||
@@ -20,3 +20,3 @@ ${JSON.stringify(s,null,4)}`);if(m(this.ranges)&&Array.isArray(this.last())&&l===this.last()[1]){if(this.last()[1]=e,this.last()[2],this.last()[2]!==null&&m(s)){let i=this.last()[2]&&this.last()[2].length&&(!((g=this.opts)!=null&&g.mergeType)||this.opts.mergeType===1)?`${this.last()[2]}${s}`:s;this.opts.limitToBeAddedWhitespace&&(i=$(i,this.opts.limitLinebreaksCount)),f(i)&&!i.length||(this.last()[2]=i)}}else{this.ranges||(this.ranges=[]);let i=s!==void 0&&!(f(s)&&!s.length)?[l,e,s&&this.opts.limitToBeAddedWhitespace?$(s,this.opts.limitLinebreaksCount):s]:[l,e];this.ranges.push(i)}}else throw h(l)&&l>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof e}" equal to: ${JSON.stringify(e,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof l}" equal to: ${JSON.stringify(l,null,4)}`)}push(n,o,s){this.add(n,o,s)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=S(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(n=>m(n[2])?[n[0],n[1],$(n[2],this.opts.limitLinebreaksCount)]:n):this.ranges):null}wipe(){this.ranges=[]}replace(n){if(Array.isArray(n)&&n.length)if(Array.isArray(n[0])&&h(n[0][0]))this.ranges=Array.from(n);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(n[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};return j(k);})(); | ||
* @fileoverview Sort string index ranges | ||
* @version 5.1.1 | ||
* @version 5.1.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -29,3 +29,3 @@ * @license MIT | ||
* @fileoverview Collapse the leading and trailing whitespace of a string | ||
* @version 6.1.2 | ||
* @version 6.1.3 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -32,0 +32,0 @@ * @license MIT |
{ | ||
"name": "ranges-push", | ||
"version": "6.2.2", | ||
"version": "6.2.3", | ||
"description": "Gather string index ranges", | ||
@@ -72,5 +72,5 @@ "keywords": [ | ||
"dependencies": { | ||
"string-collapse-leading-whitespace": "^6.1.2", | ||
"string-trim-spaces-only": "^4.1.1" | ||
"string-collapse-leading-whitespace": "^6.1.3", | ||
"string-trim-spaces-only": "^4.1.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34170