string-range-expander 4.0.8 → 4.0.9

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 CHANGED
@@ -3,6 +3,12 @@
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
+ ## 4.0.9 (2023-05-13)
7
+
8
+ ### Bug Fixes
9
+
10
+ - correct `opts.ifRightSideIncludesThisCropItToo` edge cases ([49bd408](https://github.com/codsen/codsen/commit/49bd4085167116d30f631ffc45388083becf903e))
11
+
6
12
  ## 4.0.0 (2022-12-01)
7
13
 
8
14
  ### BREAKING CHANGES
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * @name string-range-expander
3
3
  * @fileoverview Expands string index ranges within whitespace boundaries until letters are met
4
- * @version 4.0.8
4
+ * @version 4.0.9
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-range-expander/}
8
8
  */
9
9
 
10
- import{isStr as l,isInt as u,isPlainObject as T}from"codsen-utils";var h="4.0.8";var x=h,p={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};function y(i){let a=/^[0-9a-zA-Z]+$/;function o(n){return l(n)&&!n.trim()}if(T(i)){if(!Object.keys(i).length)throw new Error("string-range-expander: [THROW_ID_02] Input must be a plain object but it was given as a plain object without any keys.")}else{let n;throw i===void 0?n="but it is missing completely.":i===null?n="but it was given as null.":n=`but it was given as ${typeof i}, equal to:
11
- ${JSON.stringify(i,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${n}`)}if(!u(i.from))throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value resolvedOpts.from, is not a number! Currently it's given as ${typeof i.from}, equal to ${JSON.stringify(i.from,null,0)}`);if(!u(i.to))throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value resolvedOpts.to, is not a number! Currently it's given as ${typeof i.to}, equal to ${JSON.stringify(i.to,null,0)}`);if(i?.str&&!i.str[i.from]&&i.from!==i.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string resolvedOpts.str ("${i.str}") must contain the character at index "from" ("${i.from}")`);if(i?.str&&!i.str[i.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, resolvedOpts.str ("${i.str}") must contain the character at index before "to" ("${i.to-1}")`);if(i.from>i.to)throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${i.from}" is greater than "to" index, "${i.to}". That's wrong!`);if(i.extendToOneSide===null||l(i.extendToOneSide)&&i.extendToOneSide!=="left"&&i.extendToOneSide!=="right"||!l(i.extendToOneSide)&&i.extendToOneSide!==void 0&&i.extendToOneSide)throw new Error(`string-range-expander: [THROW_ID_08] The resolvedOpts.extendToOneSide value is not recognisable! It's set to: "${i.extendToOneSide}" (${typeof i.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);let e={...p,...i};if(Array.isArray(e.ifLeftSideIncludesThisThenCropTightly)){let n,d;if(e.ifLeftSideIncludesThisThenCropTightly.every((f,c)=>l(f)?!0:(n=c,d=f,!1)))e.ifLeftSideIncludesThisThenCropTightly=e.ifLeftSideIncludesThisThenCropTightly.join("");else throw new Error(`string-range-expander: [THROW_ID_09] The resolvedOpts.ifLeftSideIncludesThisThenCropTightly was set to an array:
12
- ${JSON.stringify(e.ifLeftSideIncludesThisThenCropTightly,null,4)}. Now, that array contains not only string elements. For example, an element at index ${n} is of a type ${typeof d} (equal to ${JSON.stringify(d,null,0)}).`)}let t=e.str,r=e.from,s=e.to;if(e.extendToOneSide!=="right"&&(o(t[r-1])&&(o(t[r-2])||e.ifLeftSideIncludesThisCropItToo.includes(t[r-2]))||t[r-1]&&e.ifLeftSideIncludesThisCropItToo.includes(t[r-1])||e.wipeAllWhitespaceOnLeft&&o(t[r-1]))){for(let n=r;n--;)if(!e.ifLeftSideIncludesThisCropItToo.includes(t[n])){if(t[n].trim()){e.wipeAllWhitespaceOnLeft||e.ifLeftSideIncludesThisCropItToo.includes(t[n+1])?r=n+1:r=n+2;break}else if(n===0){e.wipeAllWhitespaceOnLeft?r=0:r=1;break}}}if(e.extendToOneSide!=="left"&&(o(t[s])&&(e.wipeAllWhitespaceOnRight||o(t[s+1]))||e.ifRightSideIncludesThisCropItToo.includes(t[s]))){for(let n=s,d=t.length;n<d;n++)if(!e.ifRightSideIncludesThisCropItToo.includes(t[n])&&t[n]?.trim()){e.wipeAllWhitespaceOnRight||e.ifRightSideIncludesThisCropItToo.includes(t[n-1])?s=n:s=n-1;break}}return(e.extendToOneSide!=="right"&&l(e.ifLeftSideIncludesThisThenCropTightly)&&e.ifLeftSideIncludesThisThenCropTightly&&(t[r-2]&&e.ifLeftSideIncludesThisThenCropTightly.includes(t[r-2])||t[r-1]&&e.ifLeftSideIncludesThisThenCropTightly.includes(t[r-1]))||e.extendToOneSide!=="left"&&l(e.ifRightSideIncludesThisThenCropTightly)&&e.ifRightSideIncludesThisThenCropTightly&&(t[s+1]&&e.ifRightSideIncludesThisThenCropTightly.includes(t[s+1])||t[s]&&e.ifRightSideIncludesThisThenCropTightly.includes(t[s])))&&(e.extendToOneSide!=="right"&&o(t[r-1])&&!e.wipeAllWhitespaceOnLeft&&(r-=1),e.extendToOneSide!=="left"&&o(t[s])&&!e.wipeAllWhitespaceOnRight&&(s+=1)),e.addSingleSpaceToPreventAccidentalConcatenation&&t[r-1]&&t[r-1].trim()&&t[s]&&t[s].trim()&&(!e.ifLeftSideIncludesThisThenCropTightly&&!e.ifRightSideIncludesThisThenCropTightly||!((!e.ifLeftSideIncludesThisThenCropTightly||e.ifLeftSideIncludesThisThenCropTightly.includes(t[r-1]))&&(!e.ifRightSideIncludesThisThenCropTightly||t[s]&&e.ifRightSideIncludesThisThenCropTightly.includes(t[s]))))&&(a.test(t[r-1])||a.test(t[s]))?[r,s," "]:[r,s]}export{p as defaults,y as expander,x as version};
10
+ import{isStr as s,isInt as f,isPlainObject as u}from"codsen-utils";var h="4.0.9";var I=h,a={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};function S(e){let d=/^[0-9a-zA-Z]+$/;function l(t){return s(t)&&!t.trim()}if(u(e)){if(!Object.keys(e).length)throw new Error(`string-range-expander: [THROW_ID_02] Input must be a plain object but it's been given as a plain object without any keys. However, "from" and "to" settings are obligatory!`)}else{let t;throw e===void 0?t="but it is missing completely.":e===null?t="but it was given as null.":t=`but it was given as ${typeof e}, equal to:
11
+ ${JSON.stringify(e,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${t}`)}if(!f(e.from))throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value resolvedOpts.from, is not a number! It's been given as ${typeof e.from}, equal to ${JSON.stringify(e.from,null,0)}`);if(!f(e.to))throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value resolvedOpts.to, is not a number! It's been given as ${typeof e.to}, equal to ${JSON.stringify(e.to,null,0)}`);if(e?.str&&!e.str[e.from]&&e.from!==e.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string resolvedOpts.str ("${e.str}") must contain the character at index "from" ("${e.from}")`);if(e?.str&&!e.str[e.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, resolvedOpts.str ("${e.str}") must contain the character at index before "to" ("${e.to-1}")`);if(e.from>e.to)throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${e.from}" is greater than "to" index, "${e.to}". That's wrong!`);if(e.extendToOneSide===null||s(e.extendToOneSide)&&e.extendToOneSide!=="left"&&e.extendToOneSide!=="right"||!s(e.extendToOneSide)&&e.extendToOneSide!==void 0&&e.extendToOneSide)throw new Error(`string-range-expander: [THROW_ID_08] The options value "extendToOneSide" is not recognisable! It's set to: "${e.extendToOneSide}" (${typeof e.extendToOneSide}). It has to be either Boolean "false" or one of strings: "left" or "right"`);if(e?.ifLeftSideIncludesThisThenCropTightly&&!s(e.ifLeftSideIncludesThisThenCropTightly))throw new Error(`string-range-expander: [THROW_ID_09] The option "ifLeftSideIncludesThisThenCropTightly", is not a string! It's been given as ${typeof e.ifLeftSideIncludesThisThenCropTightly}, equal to ${JSON.stringify(e.ifLeftSideIncludesThisThenCropTightly,null,0)}`);if(e?.ifLeftSideIncludesThisCropItToo&&!s(e.ifLeftSideIncludesThisCropItToo))throw new Error(`string-range-expander: [THROW_ID_10] The option "ifLeftSideIncludesThisCropItToo", is not a string! It's been given as ${typeof e.ifLeftSideIncludesThisCropItToo}, equal to ${JSON.stringify(e.ifLeftSideIncludesThisCropItToo,null,0)}`);if(e?.ifRightSideIncludesThisThenCropTightly&&!s(e.ifRightSideIncludesThisThenCropTightly))throw new Error(`string-range-expander: [THROW_ID_11] The option "ifRightSideIncludesThisThenCropTightly", is not a string! It's been given as ${typeof e.ifRightSideIncludesThisThenCropTightly}, equal to ${JSON.stringify(e.ifRightSideIncludesThisThenCropTightly,null,0)}`);if(e?.ifRightSideIncludesThisCropItToo&&!s(e.ifRightSideIncludesThisCropItToo))throw new Error(`string-range-expander: [THROW_ID_12] The option "ifRightSideIncludesThisCropItToo", is not a string! It's been given as ${typeof e.ifRightSideIncludesThisCropItToo}, equal to ${JSON.stringify(e.ifRightSideIncludesThisCropItToo,null,0)}`);let i={...a,...e},n=i.str,r=i.from,o=i.to;if(i.extendToOneSide!=="right"&&(l(n[r-1])&&(l(n[r-2])||i.ifLeftSideIncludesThisCropItToo.includes(n[r-2]))||n[r-1]&&i.ifLeftSideIncludesThisCropItToo.includes(n[r-1])||i.wipeAllWhitespaceOnLeft&&l(n[r-1]))){for(let t=r;t--;)if(!i.ifLeftSideIncludesThisCropItToo.includes(n[t])){if(n[t].trim()){i.wipeAllWhitespaceOnLeft||i.ifLeftSideIncludesThisCropItToo.includes(n[t+1])?r=t+1:r=t+2;break}else if(t===0){i.wipeAllWhitespaceOnLeft?r=0:r=1;break}}}if(i.extendToOneSide!=="left"&&(l(n[o])&&(i.wipeAllWhitespaceOnRight||l(n[o+1]))||i.ifRightSideIncludesThisCropItToo.includes(n[o]))){for(let t=o,g=n.length;t<g;t++)if(!i.ifRightSideIncludesThisCropItToo.includes(n[t])){if(n[t].trim()){i.wipeAllWhitespaceOnRight||i.ifRightSideIncludesThisCropItToo.includes(n[t-1])?o=t:o=t-1;break}else if(t===n.length-1){i.wipeAllWhitespaceOnRight?o=n.length:o=n.length-1;break}}}return(i.extendToOneSide!=="right"&&s(i.ifLeftSideIncludesThisThenCropTightly)&&i.ifLeftSideIncludesThisThenCropTightly&&(n[r-2]&&i.ifLeftSideIncludesThisThenCropTightly.includes(n[r-2])||n[r-1]&&i.ifLeftSideIncludesThisThenCropTightly.includes(n[r-1]))||i.extendToOneSide!=="left"&&s(i.ifRightSideIncludesThisThenCropTightly)&&i.ifRightSideIncludesThisThenCropTightly&&(n[o+1]&&i.ifRightSideIncludesThisThenCropTightly.includes(n[o+1])||n[o]&&i.ifRightSideIncludesThisThenCropTightly.includes(n[o])))&&(i.extendToOneSide!=="right"&&l(n[r-1])&&!i.wipeAllWhitespaceOnLeft&&(r-=1),i.extendToOneSide!=="left"&&l(n[o])&&!i.wipeAllWhitespaceOnRight&&(o+=1)),i.addSingleSpaceToPreventAccidentalConcatenation&&n[r-1]?.trim()&&n[o]?.trim()&&(!i.ifLeftSideIncludesThisThenCropTightly&&!i.ifRightSideIncludesThisThenCropTightly||!((!i.ifLeftSideIncludesThisThenCropTightly||i.ifLeftSideIncludesThisThenCropTightly.includes(n[r-1]))&&(!i.ifRightSideIncludesThisThenCropTightly||n[o]&&i.ifRightSideIncludesThisThenCropTightly.includes(n[o]))))&&(d.test(n[r-1])||d.test(n[o]))?[r,o," "]:[r,o]}export{a as defaults,S as expander,I as version};
@@ -1,19 +1,18 @@
1
1
  /**
2
2
  * @name string-range-expander
3
3
  * @fileoverview Expands string index ranges within whitespace boundaries until letters are met
4
- * @version 4.0.8
4
+ * @version 4.0.9
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-range-expander/}
8
8
  */
9
9
 
10
- "use strict";var stringRangeExpander=(()=>{var d=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames,g=Object.getOwnPropertySymbols;var m=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var T=(e,n,s)=>n in e?d(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s,c=(e,n)=>{for(var s in n||(n={}))m.call(n,s)&&T(e,s,n[s]);if(g)for(var s of g(n))C.call(n,s)&&T(e,s,n[s]);return e};var I=(e,n)=>{for(var s in n)d(e,s,{get:n[s],enumerable:!0})},w=(e,n,s,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of x(n))!m.call(e,t)&&t!==s&&d(e,t,{get:()=>n[t],enumerable:!(i=O(n,t))||i.enumerable});return e};var A=e=>w(d({},"__esModule",{value:!0}),e);var E={};I(E,{defaults:()=>$,expander:()=>D,version:()=>v});function b(e){if(e==null||typeof e!="object")return!1;let n=Object.getPrototypeOf(e);return n!==null&&n!==Object.prototype&&Object.getPrototypeOf(n)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function u(e){return typeof e=="string"}function f(e){return Number.isSafeInteger(e)&&e>=0}var S="4.0.8";var v=S,$={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};function D(e){var h;let n=/^[0-9a-zA-Z]+$/;function s(r){return u(r)&&!r.trim()}if(b(e)){if(!Object.keys(e).length)throw new Error("string-range-expander: [THROW_ID_02] Input must be a plain object but it was given as a plain object without any keys.")}else{let r;throw e===void 0?r="but it is missing completely.":e===null?r="but it was given as null.":r=`but it was given as ${typeof e}, equal to:
11
- ${JSON.stringify(e,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${r}`)}if(!f(e.from))throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value resolvedOpts.from, is not a number! Currently it's given as ${typeof e.from}, equal to ${JSON.stringify(e.from,null,0)}`);if(!f(e.to))throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value resolvedOpts.to, is not a number! Currently it's given as ${typeof e.to}, equal to ${JSON.stringify(e.to,null,0)}`);if(e!=null&&e.str&&!e.str[e.from]&&e.from!==e.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string resolvedOpts.str ("${e.str}") must contain the character at index "from" ("${e.from}")`);if(e!=null&&e.str&&!e.str[e.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, resolvedOpts.str ("${e.str}") must contain the character at index before "to" ("${e.to-1}")`);if(e.from>e.to)throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${e.from}" is greater than "to" index, "${e.to}". That's wrong!`);if(e.extendToOneSide===null||u(e.extendToOneSide)&&e.extendToOneSide!=="left"&&e.extendToOneSide!=="right"||!u(e.extendToOneSide)&&e.extendToOneSide!==void 0&&e.extendToOneSide)throw new Error(`string-range-expander: [THROW_ID_08] The resolvedOpts.extendToOneSide value is not recognisable! It's set to: "${e.extendToOneSide}" (${typeof e.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);let i=c(c({},$),e);if(Array.isArray(i.ifLeftSideIncludesThisThenCropTightly)){let r,a;if(i.ifLeftSideIncludesThisThenCropTightly.every((p,y)=>u(p)?!0:(r=y,a=p,!1)))i.ifLeftSideIncludesThisThenCropTightly=i.ifLeftSideIncludesThisThenCropTightly.join("");else throw new Error(`string-range-expander: [THROW_ID_09] The resolvedOpts.ifLeftSideIncludesThisThenCropTightly was set to an array:
12
- ${JSON.stringify(i.ifLeftSideIncludesThisThenCropTightly,null,4)}. Now, that array contains not only string elements. For example, an element at index ${r} is of a type ${typeof a} (equal to ${JSON.stringify(a,null,0)}).`)}let t=i.str,o=i.from,l=i.to;if(i.extendToOneSide!=="right"&&(s(t[o-1])&&(s(t[o-2])||i.ifLeftSideIncludesThisCropItToo.includes(t[o-2]))||t[o-1]&&i.ifLeftSideIncludesThisCropItToo.includes(t[o-1])||i.wipeAllWhitespaceOnLeft&&s(t[o-1]))){for(let r=o;r--;)if(!i.ifLeftSideIncludesThisCropItToo.includes(t[r])){if(t[r].trim()){i.wipeAllWhitespaceOnLeft||i.ifLeftSideIncludesThisCropItToo.includes(t[r+1])?o=r+1:o=r+2;break}else if(r===0){i.wipeAllWhitespaceOnLeft?o=0:o=1;break}}}if(i.extendToOneSide!=="left"&&(s(t[l])&&(i.wipeAllWhitespaceOnRight||s(t[l+1]))||i.ifRightSideIncludesThisCropItToo.includes(t[l]))){for(let r=l,a=t.length;r<a;r++)if(!i.ifRightSideIncludesThisCropItToo.includes(t[r])&&((h=t[r])!=null&&h.trim())){i.wipeAllWhitespaceOnRight||i.ifRightSideIncludesThisCropItToo.includes(t[r-1])?l=r:l=r-1;break}}return(i.extendToOneSide!=="right"&&u(i.ifLeftSideIncludesThisThenCropTightly)&&i.ifLeftSideIncludesThisThenCropTightly&&(t[o-2]&&i.ifLeftSideIncludesThisThenCropTightly.includes(t[o-2])||t[o-1]&&i.ifLeftSideIncludesThisThenCropTightly.includes(t[o-1]))||i.extendToOneSide!=="left"&&u(i.ifRightSideIncludesThisThenCropTightly)&&i.ifRightSideIncludesThisThenCropTightly&&(t[l+1]&&i.ifRightSideIncludesThisThenCropTightly.includes(t[l+1])||t[l]&&i.ifRightSideIncludesThisThenCropTightly.includes(t[l])))&&(i.extendToOneSide!=="right"&&s(t[o-1])&&!i.wipeAllWhitespaceOnLeft&&(o-=1),i.extendToOneSide!=="left"&&s(t[l])&&!i.wipeAllWhitespaceOnRight&&(l+=1)),i.addSingleSpaceToPreventAccidentalConcatenation&&t[o-1]&&t[o-1].trim()&&t[l]&&t[l].trim()&&(!i.ifLeftSideIncludesThisThenCropTightly&&!i.ifRightSideIncludesThisThenCropTightly||!((!i.ifLeftSideIncludesThisThenCropTightly||i.ifLeftSideIncludesThisThenCropTightly.includes(t[o-1]))&&(!i.ifRightSideIncludesThisThenCropTightly||t[l]&&i.ifRightSideIncludesThisThenCropTightly.includes(t[l]))))&&(n.test(t[o-1])||n.test(t[l]))?[o,l," "]:[o,l]}return A(E);})();
10
+ "use strict";var stringRangeExpander=(()=>{var a=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames,g=Object.getOwnPropertySymbols;var p=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var T=(e,t,s)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,d=(e,t)=>{for(var s in t||(t={}))p.call(t,s)&&T(e,s,t[s]);if(g)for(var s of g(t))C.call(t,s)&&T(e,s,t[s]);return e};var O=(e,t)=>{for(var s in t)a(e,s,{get:t[s],enumerable:!0})},x=(e,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of y(t))!p.call(e,n)&&n!==s&&a(e,n,{get:()=>t[n],enumerable:!(i=I(t,n))||i.enumerable});return e};var w=e=>x(a({},"__esModule",{value:!0}),e);var v={};O(v,{defaults:()=>b,expander:()=>A,version:()=>E});function m(e){if(e==null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function u(e){return typeof e=="string"}function c(e){return Number.isSafeInteger(e)&&e>=0}var S="4.0.9";var E=S,b={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};function A(e){var f,h;let t=/^[0-9a-zA-Z]+$/;function s(r){return u(r)&&!r.trim()}if(m(e)){if(!Object.keys(e).length)throw new Error(`string-range-expander: [THROW_ID_02] Input must be a plain object but it's been given as a plain object without any keys. However, "from" and "to" settings are obligatory!`)}else{let r;throw e===void 0?r="but it is missing completely.":e===null?r="but it was given as null.":r=`but it was given as ${typeof e}, equal to:
11
+ ${JSON.stringify(e,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${r}`)}if(!c(e.from))throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value resolvedOpts.from, is not a number! It's been given as ${typeof e.from}, equal to ${JSON.stringify(e.from,null,0)}`);if(!c(e.to))throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value resolvedOpts.to, is not a number! It's been given as ${typeof e.to}, equal to ${JSON.stringify(e.to,null,0)}`);if(e!=null&&e.str&&!e.str[e.from]&&e.from!==e.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string resolvedOpts.str ("${e.str}") must contain the character at index "from" ("${e.from}")`);if(e!=null&&e.str&&!e.str[e.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, resolvedOpts.str ("${e.str}") must contain the character at index before "to" ("${e.to-1}")`);if(e.from>e.to)throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${e.from}" is greater than "to" index, "${e.to}". That's wrong!`);if(e.extendToOneSide===null||u(e.extendToOneSide)&&e.extendToOneSide!=="left"&&e.extendToOneSide!=="right"||!u(e.extendToOneSide)&&e.extendToOneSide!==void 0&&e.extendToOneSide)throw new Error(`string-range-expander: [THROW_ID_08] The options value "extendToOneSide" is not recognisable! It's set to: "${e.extendToOneSide}" (${typeof e.extendToOneSide}). It has to be either Boolean "false" or one of strings: "left" or "right"`);if(e!=null&&e.ifLeftSideIncludesThisThenCropTightly&&!u(e.ifLeftSideIncludesThisThenCropTightly))throw new Error(`string-range-expander: [THROW_ID_09] The option "ifLeftSideIncludesThisThenCropTightly", is not a string! It's been given as ${typeof e.ifLeftSideIncludesThisThenCropTightly}, equal to ${JSON.stringify(e.ifLeftSideIncludesThisThenCropTightly,null,0)}`);if(e!=null&&e.ifLeftSideIncludesThisCropItToo&&!u(e.ifLeftSideIncludesThisCropItToo))throw new Error(`string-range-expander: [THROW_ID_10] The option "ifLeftSideIncludesThisCropItToo", is not a string! It's been given as ${typeof e.ifLeftSideIncludesThisCropItToo}, equal to ${JSON.stringify(e.ifLeftSideIncludesThisCropItToo,null,0)}`);if(e!=null&&e.ifRightSideIncludesThisThenCropTightly&&!u(e.ifRightSideIncludesThisThenCropTightly))throw new Error(`string-range-expander: [THROW_ID_11] The option "ifRightSideIncludesThisThenCropTightly", is not a string! It's been given as ${typeof e.ifRightSideIncludesThisThenCropTightly}, equal to ${JSON.stringify(e.ifRightSideIncludesThisThenCropTightly,null,0)}`);if(e!=null&&e.ifRightSideIncludesThisCropItToo&&!u(e.ifRightSideIncludesThisCropItToo))throw new Error(`string-range-expander: [THROW_ID_12] The option "ifRightSideIncludesThisCropItToo", is not a string! It's been given as ${typeof e.ifRightSideIncludesThisCropItToo}, equal to ${JSON.stringify(e.ifRightSideIncludesThisCropItToo,null,0)}`);let i=d(d({},b),e),n=i.str,o=i.from,l=i.to;if(i.extendToOneSide!=="right"&&(s(n[o-1])&&(s(n[o-2])||i.ifLeftSideIncludesThisCropItToo.includes(n[o-2]))||n[o-1]&&i.ifLeftSideIncludesThisCropItToo.includes(n[o-1])||i.wipeAllWhitespaceOnLeft&&s(n[o-1]))){for(let r=o;r--;)if(!i.ifLeftSideIncludesThisCropItToo.includes(n[r])){if(n[r].trim()){i.wipeAllWhitespaceOnLeft||i.ifLeftSideIncludesThisCropItToo.includes(n[r+1])?o=r+1:o=r+2;break}else if(r===0){i.wipeAllWhitespaceOnLeft?o=0:o=1;break}}}if(i.extendToOneSide!=="left"&&(s(n[l])&&(i.wipeAllWhitespaceOnRight||s(n[l+1]))||i.ifRightSideIncludesThisCropItToo.includes(n[l]))){for(let r=l,$=n.length;r<$;r++)if(!i.ifRightSideIncludesThisCropItToo.includes(n[r])){if(n[r].trim()){i.wipeAllWhitespaceOnRight||i.ifRightSideIncludesThisCropItToo.includes(n[r-1])?l=r:l=r-1;break}else if(r===n.length-1){i.wipeAllWhitespaceOnRight?l=n.length:l=n.length-1;break}}}return(i.extendToOneSide!=="right"&&u(i.ifLeftSideIncludesThisThenCropTightly)&&i.ifLeftSideIncludesThisThenCropTightly&&(n[o-2]&&i.ifLeftSideIncludesThisThenCropTightly.includes(n[o-2])||n[o-1]&&i.ifLeftSideIncludesThisThenCropTightly.includes(n[o-1]))||i.extendToOneSide!=="left"&&u(i.ifRightSideIncludesThisThenCropTightly)&&i.ifRightSideIncludesThisThenCropTightly&&(n[l+1]&&i.ifRightSideIncludesThisThenCropTightly.includes(n[l+1])||n[l]&&i.ifRightSideIncludesThisThenCropTightly.includes(n[l])))&&(i.extendToOneSide!=="right"&&s(n[o-1])&&!i.wipeAllWhitespaceOnLeft&&(o-=1),i.extendToOneSide!=="left"&&s(n[l])&&!i.wipeAllWhitespaceOnRight&&(l+=1)),i.addSingleSpaceToPreventAccidentalConcatenation&&((f=n[o-1])!=null&&f.trim())&&((h=n[l])!=null&&h.trim())&&(!i.ifLeftSideIncludesThisThenCropTightly&&!i.ifRightSideIncludesThisThenCropTightly||!((!i.ifLeftSideIncludesThisThenCropTightly||i.ifLeftSideIncludesThisThenCropTightly.includes(n[o-1]))&&(!i.ifRightSideIncludesThisThenCropTightly||n[l]&&i.ifRightSideIncludesThisThenCropTightly.includes(n[l]))))&&(t.test(n[o-1])||t.test(n[l]))?[o,l," "]:[o,l]}return w(v);})();
13
12
  /**
14
13
  * @name codsen-utils
15
14
  * @fileoverview Various utility functions
16
- * @version 1.4.0
15
+ * @version 1.5.0
17
16
  * @author Roy Revelt, Codsen Ltd
18
17
  * @license MIT
19
18
  * {@link https://codsen.com/os/codsen-utils/}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-range-expander",
3
- "version": "4.0.8",
3
+ "version": "4.0.9",
4
4
  "description": "Expands string index ranges within whitespace boundaries until letters are met",
5
5
  "keywords": [
6
6
  "expand",
@@ -55,6 +55,7 @@
55
55
  "node": ">=14.18.0"
56
56
  },
57
57
  "c8": {
58
+ "branches": 100,
58
59
  "check-coverage": true,
59
60
  "exclude": [
60
61
  "**/test/**/*.*"
@@ -69,6 +70,6 @@
69
70
  }
70
71
  },
71
72
  "dependencies": {
72
- "codsen-utils": "^1.4.0"
73
+ "codsen-utils": "^1.5.0"
73
74
  }
74
75
  }