Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string-range-expander

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-range-expander - npm Package Compare versions

Comparing version 3.0.7 to 3.0.10

196

dist/string-range-expander.esm.js
/**
* @name string-range-expander
* @fileoverview Expands string index ranges within whitespace boundaries until letters are met
* @version 3.0.7
* @version 3.0.10
* @author Roy Revelt, Codsen Ltd

@@ -10,192 +10,4 @@ * @license MIT

var version$1 = "3.0.7";
const version = version$1;
const defaults = {
str: "",
from: 0,
to: 0,
ifLeftSideIncludesThisThenCropTightly: "",
ifLeftSideIncludesThisCropItToo: "",
ifRightSideIncludesThisThenCropTightly: "",
ifRightSideIncludesThisCropItToo: "",
extendToOneSide: false,
wipeAllWhitespaceOnLeft: false,
wipeAllWhitespaceOnRight: false,
addSingleSpaceToPreventAccidentalConcatenation: false,
};
function expander(originalOpts) {
const letterOrDigit = /^[0-9a-zA-Z]+$/;
function isWhitespace(char) {
if (!char || typeof char !== "string") {
return false;
}
return !char.trim();
}
function isStr(something) {
return typeof something === "string";
}
if (!originalOpts ||
typeof originalOpts !== "object" ||
Array.isArray(originalOpts)) {
let supplementalString;
if (originalOpts === undefined) {
supplementalString = "but it is missing completely.";
}
else if (originalOpts === null) {
supplementalString = "but it was given as null.";
}
else {
supplementalString = `but it was given as ${typeof originalOpts}, equal to:\n${JSON.stringify(originalOpts, null, 4)}.`;
}
throw new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${supplementalString}`);
}
else if (typeof originalOpts === "object" &&
originalOpts !== null &&
!Array.isArray(originalOpts) &&
!Object.keys(originalOpts).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.`);
}
if (typeof originalOpts.from !== "number") {
throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value opts.from, is not a number! Currently it's given as ${typeof originalOpts.from}, equal to ${JSON.stringify(originalOpts.from, null, 0)}`);
}
if (typeof originalOpts.to !== "number") {
throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value opts.to, is not a number! Currently it's given as ${typeof originalOpts.to}, equal to ${JSON.stringify(originalOpts.to, null, 0)}`);
}
if (originalOpts &&
originalOpts.str &&
!originalOpts.str[originalOpts.from] &&
originalOpts.from !== originalOpts.to) {
throw new Error(`string-range-expander: [THROW_ID_05] The given input string opts.str ("${originalOpts.str}") must contain the character at index "from" ("${originalOpts.from}")`);
}
if (originalOpts &&
originalOpts.str &&
!originalOpts.str[originalOpts.to - 1]) {
throw new Error(`string-range-expander: [THROW_ID_06] The given input string, opts.str ("${originalOpts.str}") must contain the character at index before "to" ("${originalOpts.to - 1}")`);
}
if (originalOpts.from > originalOpts.to) {
throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${originalOpts.from}" is greater than "to" index, "${originalOpts.to}". That's wrong!`);
}
if ((isStr(originalOpts.extendToOneSide) &&
originalOpts.extendToOneSide !== "left" &&
originalOpts.extendToOneSide !== "right") ||
(!isStr(originalOpts.extendToOneSide) &&
originalOpts.extendToOneSide !== undefined &&
originalOpts.extendToOneSide !== false)) {
throw new Error(`string-range-expander: [THROW_ID_08] The opts.extendToOneSide value is not recogniseable! It's set to: "${originalOpts.extendToOneSide}" (${typeof originalOpts.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);
}
const opts = { ...defaults, ...originalOpts };
if (Array.isArray(opts.ifLeftSideIncludesThisThenCropTightly)) {
let culpritsIndex;
let culpritsValue;
if (opts.ifLeftSideIncludesThisThenCropTightly.every((val, i) => {
if (!isStr(val)) {
culpritsIndex = i;
culpritsValue = val;
return false;
}
return true;
})) {
opts.ifLeftSideIncludesThisThenCropTightly =
opts.ifLeftSideIncludesThisThenCropTightly.join("");
}
else {
throw new Error(`string-range-expander: [THROW_ID_09] The opts.ifLeftSideIncludesThisThenCropTightly was set to an array:\n${JSON.stringify(opts.ifLeftSideIncludesThisThenCropTightly, null, 4)}. Now, that array contains not only string elements. For example, an element at index ${culpritsIndex} is of a type ${typeof culpritsValue} (equal to ${JSON.stringify(culpritsValue, null, 0)}).`);
}
}
const str = opts.str;
let from = opts.from;
let to = opts.to;
if (opts.extendToOneSide !== "right" &&
((isWhitespace(str[from - 1]) &&
(isWhitespace(str[from - 2]) ||
opts.ifLeftSideIncludesThisCropItToo.includes(str[from - 2]))) ||
(str[from - 1] &&
opts.ifLeftSideIncludesThisCropItToo.includes(str[from - 1])) ||
(opts.wipeAllWhitespaceOnLeft && isWhitespace(str[from - 1])))) {
for (let i = from; i--;) {
if (!opts.ifLeftSideIncludesThisCropItToo.includes(str[i])) {
if (str[i].trim()) {
if (opts.wipeAllWhitespaceOnLeft ||
opts.ifLeftSideIncludesThisCropItToo.includes(str[i + 1])) {
from = i + 1;
}
else {
from = i + 2;
}
break;
}
else if (i === 0) {
if (opts.wipeAllWhitespaceOnLeft) {
from = 0;
}
else {
from = 1;
}
break;
}
}
}
}
if (opts.extendToOneSide !== "left" &&
((isWhitespace(str[to]) &&
(opts.wipeAllWhitespaceOnRight || isWhitespace(str[to + 1]))) ||
opts.ifRightSideIncludesThisCropItToo.includes(str[to]))) {
for (let i = to, len = str.length; i < len; i++) {
if (!opts.ifRightSideIncludesThisCropItToo.includes(str[i]) &&
((str[i] && str[i].trim()) || str[i] === undefined)) {
if (opts.wipeAllWhitespaceOnRight ||
opts.ifRightSideIncludesThisCropItToo.includes(str[i - 1])) {
to = i;
}
else {
to = i - 1;
}
break;
}
}
}
if ((opts.extendToOneSide !== "right" &&
isStr(opts.ifLeftSideIncludesThisThenCropTightly) &&
opts.ifLeftSideIncludesThisThenCropTightly &&
((str[from - 2] &&
opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 2])) ||
(str[from - 1] &&
opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 1])))) ||
(opts.extendToOneSide !== "left" &&
isStr(opts.ifRightSideIncludesThisThenCropTightly) &&
opts.ifRightSideIncludesThisThenCropTightly &&
((str[to + 1] &&
opts.ifRightSideIncludesThisThenCropTightly.includes(str[to + 1])) ||
(str[to] &&
opts.ifRightSideIncludesThisThenCropTightly.includes(str[to]))))) {
if (opts.extendToOneSide !== "right" &&
isWhitespace(str[from - 1]) &&
!opts.wipeAllWhitespaceOnLeft) {
from -= 1;
}
if (opts.extendToOneSide !== "left" &&
isWhitespace(str[to]) &&
!opts.wipeAllWhitespaceOnRight) {
to += 1;
}
}
if (opts.addSingleSpaceToPreventAccidentalConcatenation &&
str[from - 1] &&
str[from - 1].trim() &&
str[to] &&
str[to].trim() &&
((!opts.ifLeftSideIncludesThisThenCropTightly &&
!opts.ifRightSideIncludesThisThenCropTightly) ||
!((!opts.ifLeftSideIncludesThisThenCropTightly ||
opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 1])) &&
(!opts.ifRightSideIncludesThisThenCropTightly ||
(str[to] &&
opts.ifRightSideIncludesThisThenCropTightly.includes(str[to]))))) &&
(letterOrDigit.test(str[from - 1]) || letterOrDigit.test(str[to]))) {
return [from, to, " "];
}
return [from, to];
}
export { defaults, expander, version };
var u="3.0.10";var m=u,a={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};function y(t){let f=/^[0-9a-zA-Z]+$/;function s(i){return!i||typeof i!="string"?!1:!i.trim()}function l(i){return typeof i=="string"}if(!t||typeof t!="object"||Array.isArray(t)){let i;throw t===void 0?i="but it is missing completely.":t===null?i="but it was given as null.":i=`but it was given as ${typeof t}, equal to:
${JSON.stringify(t,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${i}`)}else if(typeof t=="object"&&t!==null&&!Array.isArray(t)&&!Object.keys(t).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.");if(typeof t.from!="number")throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value opts.from, is not a number! Currently it's given as ${typeof t.from}, equal to ${JSON.stringify(t.from,null,0)}`);if(typeof t.to!="number")throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value opts.to, is not a number! Currently it's given as ${typeof t.to}, equal to ${JSON.stringify(t.to,null,0)}`);if(t?.str&&!t.str[t.from]&&t.from!==t.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string opts.str ("${t.str}") must contain the character at index "from" ("${t.from}")`);if(t?.str&&!t.str[t.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, opts.str ("${t.str}") must contain the character at index before "to" ("${t.to-1}")`);if(t.from>t.to)throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${t.from}" is greater than "to" index, "${t.to}". That's wrong!`);if(l(t.extendToOneSide)&&t.extendToOneSide!=="left"&&t.extendToOneSide!=="right"||!l(t.extendToOneSide)&&t.extendToOneSide!==void 0&&t.extendToOneSide!==!1)throw new Error(`string-range-expander: [THROW_ID_08] The opts.extendToOneSide value is not recogniseable! It's set to: "${t.extendToOneSide}" (${typeof t.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);let e={...a,...t};if(Array.isArray(e.ifLeftSideIncludesThisThenCropTightly)){let i,d;if(e.ifLeftSideIncludesThisThenCropTightly.every((h,c)=>l(h)?!0:(i=c,d=h,!1)))e.ifLeftSideIncludesThisThenCropTightly=e.ifLeftSideIncludesThisThenCropTightly.join("");else throw new Error(`string-range-expander: [THROW_ID_09] The opts.ifLeftSideIncludesThisThenCropTightly was set to an array:
${JSON.stringify(e.ifLeftSideIncludesThisThenCropTightly,null,4)}. Now, that array contains not only string elements. For example, an element at index ${i} is of a type ${typeof d} (equal to ${JSON.stringify(d,null,0)}).`)}let n=e.str,r=e.from,o=e.to;if(e.extendToOneSide!=="right"&&(s(n[r-1])&&(s(n[r-2])||e.ifLeftSideIncludesThisCropItToo.includes(n[r-2]))||n[r-1]&&e.ifLeftSideIncludesThisCropItToo.includes(n[r-1])||e.wipeAllWhitespaceOnLeft&&s(n[r-1]))){for(let i=r;i--;)if(!e.ifLeftSideIncludesThisCropItToo.includes(n[i])){if(n[i].trim()){e.wipeAllWhitespaceOnLeft||e.ifLeftSideIncludesThisCropItToo.includes(n[i+1])?r=i+1:r=i+2;break}else if(i===0){e.wipeAllWhitespaceOnLeft?r=0:r=1;break}}}if(e.extendToOneSide!=="left"&&(s(n[o])&&(e.wipeAllWhitespaceOnRight||s(n[o+1]))||e.ifRightSideIncludesThisCropItToo.includes(n[o]))){for(let i=o,d=n.length;i<d;i++)if(!e.ifRightSideIncludesThisCropItToo.includes(n[i])&&n[i]?.trim()){e.wipeAllWhitespaceOnRight||e.ifRightSideIncludesThisCropItToo.includes(n[i-1])?o=i:o=i-1;break}}return(e.extendToOneSide!=="right"&&l(e.ifLeftSideIncludesThisThenCropTightly)&&e.ifLeftSideIncludesThisThenCropTightly&&(n[r-2]&&e.ifLeftSideIncludesThisThenCropTightly.includes(n[r-2])||n[r-1]&&e.ifLeftSideIncludesThisThenCropTightly.includes(n[r-1]))||e.extendToOneSide!=="left"&&l(e.ifRightSideIncludesThisThenCropTightly)&&e.ifRightSideIncludesThisThenCropTightly&&(n[o+1]&&e.ifRightSideIncludesThisThenCropTightly.includes(n[o+1])||n[o]&&e.ifRightSideIncludesThisThenCropTightly.includes(n[o])))&&(e.extendToOneSide!=="right"&&s(n[r-1])&&!e.wipeAllWhitespaceOnLeft&&(r-=1),e.extendToOneSide!=="left"&&s(n[o])&&!e.wipeAllWhitespaceOnRight&&(o+=1)),e.addSingleSpaceToPreventAccidentalConcatenation&&n[r-1]&&n[r-1].trim()&&n[o]&&n[o].trim()&&(!e.ifLeftSideIncludesThisThenCropTightly&&!e.ifRightSideIncludesThisThenCropTightly||!((!e.ifLeftSideIncludesThisThenCropTightly||e.ifLeftSideIncludesThisThenCropTightly.includes(n[r-1]))&&(!e.ifRightSideIncludesThisThenCropTightly||n[o]&&e.ifRightSideIncludesThisThenCropTightly.includes(n[o]))))&&(f.test(n[r-1])||f.test(n[o]))?[r,o," "]:[r,o]}export{a as defaults,y as expander,m as version};

6

dist/string-range-expander.umd.js
/**
* @name string-range-expander
* @fileoverview Expands string index ranges within whitespace boundaries until letters are met
* @version 3.0.7
* @version 3.0.10
* @author Roy Revelt, Codsen Ltd

@@ -10,2 +10,4 @@ * @license MIT

!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((e="undefined"!=typeof globalThis?globalThis:e||self).stringRangeExpander={})}(this,(function(e){"use strict";const i={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};e.defaults=i,e.expander=function(e){const t=/^[0-9a-zA-Z]+$/;function n(e){return!(!e||"string"!=typeof e)&&!e.trim()}function r(e){return"string"==typeof e}if(!e||"object"!=typeof e||Array.isArray(e)){let i;throw i=void 0===e?"but it is missing completely.":null===e?"but it was given as null.":`but it was given as ${typeof e}, equal to:\n${JSON.stringify(e,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${i}`)}if("object"==typeof e&&null!==e&&!Array.isArray(e)&&!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.");if("number"!=typeof e.from)throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value opts.from, is not a number! Currently it's given as ${typeof e.from}, equal to ${JSON.stringify(e.from,null,0)}`);if("number"!=typeof e.to)throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value opts.to, is not a number! Currently it's given as ${typeof e.to}, equal to ${JSON.stringify(e.to,null,0)}`);if(e&&e.str&&!e.str[e.from]&&e.from!==e.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string opts.str ("${e.str}") must contain the character at index "from" ("${e.from}")`);if(e&&e.str&&!e.str[e.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, opts.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(r(e.extendToOneSide)&&"left"!==e.extendToOneSide&&"right"!==e.extendToOneSide||!r(e.extendToOneSide)&&void 0!==e.extendToOneSide&&!1!==e.extendToOneSide)throw new Error(`string-range-expander: [THROW_ID_08] The opts.extendToOneSide value is not recogniseable! It's set to: "${e.extendToOneSide}" (${typeof e.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);const o={...i,...e};if(Array.isArray(o.ifLeftSideIncludesThisThenCropTightly)){let e,i;if(!o.ifLeftSideIncludesThisThenCropTightly.every(((t,n)=>!!r(t)||(e=n,i=t,!1))))throw new Error(`string-range-expander: [THROW_ID_09] The opts.ifLeftSideIncludesThisThenCropTightly was set to an array:\n${JSON.stringify(o.ifLeftSideIncludesThisThenCropTightly,null,4)}. Now, that array contains not only string elements. For example, an element at index ${e} is of a type ${typeof i} (equal to ${JSON.stringify(i,null,0)}).`);o.ifLeftSideIncludesThisThenCropTightly=o.ifLeftSideIncludesThisThenCropTightly.join("")}const s=o.str;let l=o.from,d=o.to;if("right"!==o.extendToOneSide&&(n(s[l-1])&&(n(s[l-2])||o.ifLeftSideIncludesThisCropItToo.includes(s[l-2]))||s[l-1]&&o.ifLeftSideIncludesThisCropItToo.includes(s[l-1])||o.wipeAllWhitespaceOnLeft&&n(s[l-1])))for(let e=l;e--;)if(!o.ifLeftSideIncludesThisCropItToo.includes(s[e])){if(s[e].trim()){l=o.wipeAllWhitespaceOnLeft||o.ifLeftSideIncludesThisCropItToo.includes(s[e+1])?e+1:e+2;break}if(0===e){l=o.wipeAllWhitespaceOnLeft?0:1;break}}if("left"!==o.extendToOneSide&&(n(s[d])&&(o.wipeAllWhitespaceOnRight||n(s[d+1]))||o.ifRightSideIncludesThisCropItToo.includes(s[d])))for(let e=d,i=s.length;e<i;e++)if(!o.ifRightSideIncludesThisCropItToo.includes(s[e])&&(s[e]&&s[e].trim()||void 0===s[e])){d=o.wipeAllWhitespaceOnRight||o.ifRightSideIncludesThisCropItToo.includes(s[e-1])?e:e-1;break}return("right"!==o.extendToOneSide&&r(o.ifLeftSideIncludesThisThenCropTightly)&&o.ifLeftSideIncludesThisThenCropTightly&&(s[l-2]&&o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-2])||s[l-1]&&o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-1]))||"left"!==o.extendToOneSide&&r(o.ifRightSideIncludesThisThenCropTightly)&&o.ifRightSideIncludesThisThenCropTightly&&(s[d+1]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d+1])||s[d]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d])))&&("right"!==o.extendToOneSide&&n(s[l-1])&&!o.wipeAllWhitespaceOnLeft&&(l-=1),"left"!==o.extendToOneSide&&n(s[d])&&!o.wipeAllWhitespaceOnRight&&(d+=1)),o.addSingleSpaceToPreventAccidentalConcatenation&&s[l-1]&&s[l-1].trim()&&s[d]&&s[d].trim()&&(!o.ifLeftSideIncludesThisThenCropTightly&&!o.ifRightSideIncludesThisThenCropTightly||o.ifLeftSideIncludesThisThenCropTightly&&!o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-1])||!(!o.ifRightSideIncludesThisThenCropTightly||s[d]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d])))&&(t.test(s[l-1])||t.test(s[d]))?[l,d," "]:[l,d]},e.version="3.0.7",Object.defineProperty(e,"__esModule",{value:!0})}));
var stringRangeExpander=(()=>{var h=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames,a=Object.getOwnPropertySymbols;var p=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var m=(e,r,o)=>r in e?h(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,u=(e,r)=>{for(var o in r||(r={}))p.call(r,o)&&m(e,o,r[o]);if(a)for(var o of a(r))b.call(r,o)&&m(e,o,r[o]);return e};var x=e=>h(e,"__esModule",{value:!0});var R=(e,r)=>{for(var o in r)h(e,o,{get:r[o],enumerable:!0})},w=(e,r,o,d)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of I(r))!p.call(e,t)&&(o||t!=="default")&&h(e,t,{get:()=>r[t],enumerable:!(d=S(r,t))||d.enumerable});return e};var C=(e=>(r,o)=>e&&e.get(r)||(o=w(x({}),r,1),e&&e.set(r,o),o))(typeof WeakMap!="undefined"?new WeakMap:0);var D={};R(D,{defaults:()=>y,expander:()=>A,version:()=>L});var g="3.0.10";var L=g,y={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};function A(e){var c;let r=/^[0-9a-zA-Z]+$/;function o(i){return!i||typeof i!="string"?!1:!i.trim()}function d(i){return typeof i=="string"}if(!e||typeof e!="object"||Array.isArray(e)){let i;throw e===void 0?i="but it is missing completely.":e===null?i="but it was given as null.":i=`but it was given as ${typeof e}, equal to:
${JSON.stringify(e,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${i}`)}else if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&!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.");if(typeof e.from!="number")throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value opts.from, is not a number! Currently it's given as ${typeof e.from}, equal to ${JSON.stringify(e.from,null,0)}`);if(typeof e.to!="number")throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value opts.to, is not a number! Currently it's given as ${typeof e.to}, equal to ${JSON.stringify(e.to,null,0)}`);if((e==null?void 0:e.str)&&!e.str[e.from]&&e.from!==e.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string opts.str ("${e.str}") must contain the character at index "from" ("${e.from}")`);if((e==null?void 0:e.str)&&!e.str[e.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, opts.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(d(e.extendToOneSide)&&e.extendToOneSide!=="left"&&e.extendToOneSide!=="right"||!d(e.extendToOneSide)&&e.extendToOneSide!==void 0&&e.extendToOneSide!==!1)throw new Error(`string-range-expander: [THROW_ID_08] The opts.extendToOneSide value is not recogniseable! It's set to: "${e.extendToOneSide}" (${typeof e.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);let t=u(u({},y),e);if(Array.isArray(t.ifLeftSideIncludesThisThenCropTightly)){let i,f;if(t.ifLeftSideIncludesThisThenCropTightly.every((T,$)=>d(T)?!0:(i=$,f=T,!1)))t.ifLeftSideIncludesThisThenCropTightly=t.ifLeftSideIncludesThisThenCropTightly.join("");else throw new Error(`string-range-expander: [THROW_ID_09] The opts.ifLeftSideIncludesThisThenCropTightly was set to an array:
${JSON.stringify(t.ifLeftSideIncludesThisThenCropTightly,null,4)}. Now, that array contains not only string elements. For example, an element at index ${i} is of a type ${typeof f} (equal to ${JSON.stringify(f,null,0)}).`)}let n=t.str,s=t.from,l=t.to;if(t.extendToOneSide!=="right"&&(o(n[s-1])&&(o(n[s-2])||t.ifLeftSideIncludesThisCropItToo.includes(n[s-2]))||n[s-1]&&t.ifLeftSideIncludesThisCropItToo.includes(n[s-1])||t.wipeAllWhitespaceOnLeft&&o(n[s-1]))){for(let i=s;i--;)if(!t.ifLeftSideIncludesThisCropItToo.includes(n[i])){if(n[i].trim()){t.wipeAllWhitespaceOnLeft||t.ifLeftSideIncludesThisCropItToo.includes(n[i+1])?s=i+1:s=i+2;break}else if(i===0){t.wipeAllWhitespaceOnLeft?s=0:s=1;break}}}if(t.extendToOneSide!=="left"&&(o(n[l])&&(t.wipeAllWhitespaceOnRight||o(n[l+1]))||t.ifRightSideIncludesThisCropItToo.includes(n[l]))){for(let i=l,f=n.length;i<f;i++)if(!t.ifRightSideIncludesThisCropItToo.includes(n[i])&&((c=n[i])==null?void 0:c.trim())){t.wipeAllWhitespaceOnRight||t.ifRightSideIncludesThisCropItToo.includes(n[i-1])?l=i:l=i-1;break}}return(t.extendToOneSide!=="right"&&d(t.ifLeftSideIncludesThisThenCropTightly)&&t.ifLeftSideIncludesThisThenCropTightly&&(n[s-2]&&t.ifLeftSideIncludesThisThenCropTightly.includes(n[s-2])||n[s-1]&&t.ifLeftSideIncludesThisThenCropTightly.includes(n[s-1]))||t.extendToOneSide!=="left"&&d(t.ifRightSideIncludesThisThenCropTightly)&&t.ifRightSideIncludesThisThenCropTightly&&(n[l+1]&&t.ifRightSideIncludesThisThenCropTightly.includes(n[l+1])||n[l]&&t.ifRightSideIncludesThisThenCropTightly.includes(n[l])))&&(t.extendToOneSide!=="right"&&o(n[s-1])&&!t.wipeAllWhitespaceOnLeft&&(s-=1),t.extendToOneSide!=="left"&&o(n[l])&&!t.wipeAllWhitespaceOnRight&&(l+=1)),t.addSingleSpaceToPreventAccidentalConcatenation&&n[s-1]&&n[s-1].trim()&&n[l]&&n[l].trim()&&(!t.ifLeftSideIncludesThisThenCropTightly&&!t.ifRightSideIncludesThisThenCropTightly||!((!t.ifLeftSideIncludesThisThenCropTightly||t.ifLeftSideIncludesThisThenCropTightly.includes(n[s-1]))&&(!t.ifRightSideIncludesThisThenCropTightly||n[l]&&t.ifRightSideIncludesThisThenCropTightly.includes(n[l]))))&&(r.test(n[s-1])||r.test(n[l]))?[s,l," "]:[s,l]}return C(D);})();
// Quick Take
import { strict as assert } from "assert";
import { expander } from "../dist/string-range-expander.esm.js";

@@ -5,0 +6,0 @@

{
"name": "string-range-expander",
"version": "3.0.7",
"version": "3.0.10",
"description": "Expands string index ranges within whitespace boundaries until letters are met",

@@ -35,31 +35,24 @@ "keywords": [

"scripts": {
"build": "rollup -c",
"build:esbuild": "node '../../scripts/esbuild.js'",
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
"clean_types": "../../scripts/cleanTypes.js",
"dev": "rollup -c --dev",
"devunittest": "npm run dev && tap --only -R 'base'",
"format": "npm run lect && npm run prettier && npm run lint",
"lect": "lect",
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
"perf": "node perf/check",
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
"republish": "npm publish || :",
"tap": "tap",
"pretest": "npm run build",
"test": "npm run test:ci && npm run perf",
"test:ci": "npm run unittest && npm run test:examples && npm run format",
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
"tsc": "tsc",
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
"dts": "rollup -c",
"examples": "node '../../ops/scripts/run-examples.js'",
"lect": "node '../../ops/lect/lect.js'",
"letspublish": "yarn publish || :",
"lint": "eslint . --fix",
"perf": "node perf/check.js",
"prepare": "echo 'ready'",
"pretest": "yarn run lect && yarn run build",
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
"unit": "uvu test"
},
"tap": {
"check-coverage": false,
"node-arg": [
"--no-warnings",
"--experimental-loader",
"@istanbuljs/esm-loader-hook"
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"c8": {
"check-coverage": true,
"exclude": [
"**/test/**/*.*"
],
"timeout": 0
"lines": 100
},

@@ -71,52 +64,4 @@ "lect": {

]
},
"req": "{ expander }",
"various": {
"devDependencies": []
}
},
"dependencies": {
"@babel/runtime": "^7.16.3"
},
"devDependencies": {
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0",
"@babel/node": "^7.16.0",
"@babel/plugin-external-helpers": "^7.16.0",
"@babel/plugin-proposal-class-properties": "^7.16.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.4",
"@babel/preset-env": "^7.16.4",
"@babel/preset-typescript": "^7.16.0",
"@babel/register": "^7.16.0",
"@istanbuljs/esm-loader-hook": "^0.1.2",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-strip": "^2.1.0",
"@rollup/plugin-typescript": "^8.3.0",
"@types/node": "^16.11.10",
"@types/tap": "^15.0.5",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"core-js": "^3.19.2",
"cross-env": "^7.0.3",
"eslint": "^8.3.0",
"lect": "^0.18.7",
"rollup": "^2.60.1",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-dts": "^4.0.1",
"rollup-plugin-terser": "^7.0.2",
"tap": "^15.1.5",
"tslib": "^2.3.1",
"typescript": "^4.5.2"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}

@@ -41,2 +41,3 @@ # string-range-expander

import { strict as assert } from "assert";
import { expander } from "string-range-expander";

@@ -64,3 +65,3 @@

Please [visit codsen.com](https://codsen.com/os/string-range-expander/) for a full description of the API and examples.
Please [visit codsen.com](https://codsen.com/os/string-range-expander/) for a full description of the API.

@@ -77,2 +78,4 @@ ## Contributing

<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">
declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
declare const version: string;
interface Opts {

@@ -6,0 +5,0 @@ str: string;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc