string-range-expander 3.0.2 → 3.0.6

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,12 +3,6 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## 3.0.1 (2021-09-13)
7
-
8
- ### Bug Fixes
9
-
10
- - bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
11
-
12
6
  ## 3.0.0 (2021-09-09)
13
7
 
14
8
  ### Features
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-%YEAR% Roy Revelt and other contributors
3
+ Copyright (c) 2010-2021 Roy Revelt and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -1,137 +1,200 @@
1
1
  /**
2
2
  * @name string-range-expander
3
3
  * @fileoverview Expands string index ranges within whitespace boundaries until letters are met
4
- * @version 3.0.2
4
+ * @version 3.0.6
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
- var version$1 = "3.0.2";
10
+ var version$1 = "3.0.6";
11
11
 
12
12
  const version = version$1;
13
13
  const defaults = {
14
- str: "",
15
- from: 0,
16
- to: 0,
17
- ifLeftSideIncludesThisThenCropTightly: "",
18
- ifLeftSideIncludesThisCropItToo: "",
19
- ifRightSideIncludesThisThenCropTightly: "",
20
- ifRightSideIncludesThisCropItToo: "",
21
- extendToOneSide: false,
22
- wipeAllWhitespaceOnLeft: false,
23
- wipeAllWhitespaceOnRight: false,
24
- addSingleSpaceToPreventAccidentalConcatenation: false
14
+ str: "",
15
+ from: 0,
16
+ to: 0,
17
+ ifLeftSideIncludesThisThenCropTightly: "",
18
+ ifLeftSideIncludesThisCropItToo: "",
19
+ ifRightSideIncludesThisThenCropTightly: "",
20
+ ifRightSideIncludesThisCropItToo: "",
21
+ extendToOneSide: false,
22
+ wipeAllWhitespaceOnLeft: false,
23
+ wipeAllWhitespaceOnRight: false,
24
+ addSingleSpaceToPreventAccidentalConcatenation: false,
25
25
  };
26
26
  function expander(originalOpts) {
27
- const letterOrDigit = /^[0-9a-zA-Z]+$/;
28
- function isWhitespace(char) {
29
- if (!char || typeof char !== "string") {
30
- return false;
27
+ const letterOrDigit = /^[0-9a-zA-Z]+$/;
28
+ function isWhitespace(char) {
29
+ if (!char || typeof char !== "string") {
30
+ return false;
31
+ }
32
+ return !char.trim();
33
+ }
34
+ function isStr(something) {
35
+ return typeof something === "string";
36
+ }
37
+ if (!originalOpts ||
38
+ typeof originalOpts !== "object" ||
39
+ Array.isArray(originalOpts)) {
40
+ let supplementalString;
41
+ if (originalOpts === undefined) {
42
+ supplementalString = "but it is missing completely.";
43
+ }
44
+ else if (originalOpts === null) {
45
+ supplementalString = "but it was given as null.";
46
+ }
47
+ else {
48
+ supplementalString = `but it was given as ${typeof originalOpts}, equal to:\n${JSON.stringify(originalOpts, null, 4)}.`;
49
+ }
50
+ throw new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${supplementalString}`);
51
+ }
52
+ else if (typeof originalOpts === "object" &&
53
+ originalOpts !== null &&
54
+ !Array.isArray(originalOpts) &&
55
+ !Object.keys(originalOpts).length) {
56
+ 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.`);
57
+ }
58
+ if (typeof originalOpts.from !== "number") {
59
+ 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)}`);
31
60
  }
32
- return !char.trim();
33
- }
34
- function isStr(something) {
35
- return typeof something === "string";
36
- }
37
- if (!originalOpts || typeof originalOpts !== "object" || Array.isArray(originalOpts)) {
38
- let supplementalString;
39
- if (originalOpts === undefined) {
40
- supplementalString = "but it is missing completely.";
41
- } else if (originalOpts === null) {
42
- supplementalString = "but it was given as null.";
43
- } else {
44
- supplementalString = `but it was given as ${typeof originalOpts}, equal to:\n${JSON.stringify(originalOpts, null, 4)}.`;
61
+ if (typeof originalOpts.to !== "number") {
62
+ 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)}`);
45
63
  }
46
- throw new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${supplementalString}`);
47
- } else if (typeof originalOpts === "object" && originalOpts !== null && !Array.isArray(originalOpts) && !Object.keys(originalOpts).length) {
48
- 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.`);
49
- }
50
- if (typeof originalOpts.from !== "number") {
51
- 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)}`);
52
- }
53
- if (typeof originalOpts.to !== "number") {
54
- 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)}`);
55
- }
56
- if (originalOpts && originalOpts.str && !originalOpts.str[originalOpts.from] && originalOpts.from !== originalOpts.to) {
57
- 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}")`);
58
- }
59
- if (originalOpts && originalOpts.str && !originalOpts.str[originalOpts.to - 1]) {
60
- 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}")`);
61
- }
62
- if (originalOpts.from > originalOpts.to) {
63
- 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!`);
64
- }
65
- if (isStr(originalOpts.extendToOneSide) && originalOpts.extendToOneSide !== "left" && originalOpts.extendToOneSide !== "right" || !isStr(originalOpts.extendToOneSide) && originalOpts.extendToOneSide !== undefined && originalOpts.extendToOneSide !== false) {
66
- 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"`);
67
- }
68
- const opts = { ...defaults,
69
- ...originalOpts
70
- };
71
- if (Array.isArray(opts.ifLeftSideIncludesThisThenCropTightly)) {
72
- let culpritsIndex;
73
- let culpritsValue;
74
- if (opts.ifLeftSideIncludesThisThenCropTightly.every((val, i) => {
75
- if (!isStr(val)) {
76
- culpritsIndex = i;
77
- culpritsValue = val;
78
- return false;
79
- }
80
- return true;
81
- })) {
82
- opts.ifLeftSideIncludesThisThenCropTightly = opts.ifLeftSideIncludesThisThenCropTightly.join("");
83
- } else {
84
- 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)}).`);
64
+ if (originalOpts &&
65
+ originalOpts.str &&
66
+ !originalOpts.str[originalOpts.from] &&
67
+ originalOpts.from !== originalOpts.to) {
68
+ 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}")`);
85
69
  }
86
- }
87
- const str = opts.str;
88
- let from = opts.from;
89
- let to = opts.to;
90
- 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]))) {
91
- for (let i = from; i--;) {
92
- if (!opts.ifLeftSideIncludesThisCropItToo.includes(str[i])) {
93
- if (str[i].trim()) {
94
- if (opts.wipeAllWhitespaceOnLeft || opts.ifLeftSideIncludesThisCropItToo.includes(str[i + 1])) {
95
- from = i + 1;
96
- } else {
97
- from = i + 2;
98
- }
99
- break;
100
- } else if (i === 0) {
101
- if (opts.wipeAllWhitespaceOnLeft) {
102
- from = 0;
103
- } else {
104
- from = 1;
105
- }
106
- break;
70
+ if (originalOpts &&
71
+ originalOpts.str &&
72
+ !originalOpts.str[originalOpts.to - 1]) {
73
+ 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}")`);
74
+ }
75
+ if (originalOpts.from > originalOpts.to) {
76
+ 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!`);
77
+ }
78
+ if ((isStr(originalOpts.extendToOneSide) &&
79
+ originalOpts.extendToOneSide !== "left" &&
80
+ originalOpts.extendToOneSide !== "right") ||
81
+ (!isStr(originalOpts.extendToOneSide) &&
82
+ originalOpts.extendToOneSide !== undefined &&
83
+ originalOpts.extendToOneSide !== false)) {
84
+ 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"`);
85
+ }
86
+ const opts = { ...defaults, ...originalOpts };
87
+ if (Array.isArray(opts.ifLeftSideIncludesThisThenCropTightly)) {
88
+ let culpritsIndex;
89
+ let culpritsValue;
90
+ if (opts.ifLeftSideIncludesThisThenCropTightly.every((val, i) => {
91
+ if (!isStr(val)) {
92
+ culpritsIndex = i;
93
+ culpritsValue = val;
94
+ return false;
95
+ }
96
+ return true;
97
+ })) {
98
+ opts.ifLeftSideIncludesThisThenCropTightly =
99
+ opts.ifLeftSideIncludesThisThenCropTightly.join("");
100
+ }
101
+ else {
102
+ 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)}).`);
107
103
  }
108
- }
109
104
  }
110
- }
111
- if (opts.extendToOneSide !== "left" && (isWhitespace(str[to]) && (opts.wipeAllWhitespaceOnRight || isWhitespace(str[to + 1])) || opts.ifRightSideIncludesThisCropItToo.includes(str[to]))) {
112
- for (let i = to, len = str.length; i < len; i++) {
113
- if (!opts.ifRightSideIncludesThisCropItToo.includes(str[i]) && (str[i] && str[i].trim() || str[i] === undefined)) {
114
- if (opts.wipeAllWhitespaceOnRight || opts.ifRightSideIncludesThisCropItToo.includes(str[i - 1])) {
115
- to = i;
116
- } else {
117
- to = i - 1;
105
+ const str = opts.str;
106
+ let from = opts.from;
107
+ let to = opts.to;
108
+ if (opts.extendToOneSide !== "right" &&
109
+ ((isWhitespace(str[from - 1]) &&
110
+ (isWhitespace(str[from - 2]) ||
111
+ opts.ifLeftSideIncludesThisCropItToo.includes(str[from - 2]))) ||
112
+ (str[from - 1] &&
113
+ opts.ifLeftSideIncludesThisCropItToo.includes(str[from - 1])) ||
114
+ (opts.wipeAllWhitespaceOnLeft && isWhitespace(str[from - 1])))) {
115
+ for (let i = from; i--;) {
116
+ if (!opts.ifLeftSideIncludesThisCropItToo.includes(str[i])) {
117
+ if (str[i].trim()) {
118
+ if (opts.wipeAllWhitespaceOnLeft ||
119
+ opts.ifLeftSideIncludesThisCropItToo.includes(str[i + 1])) {
120
+ from = i + 1;
121
+ }
122
+ else {
123
+ from = i + 2;
124
+ }
125
+ break;
126
+ }
127
+ else if (i === 0) {
128
+ if (opts.wipeAllWhitespaceOnLeft) {
129
+ from = 0;
130
+ }
131
+ else {
132
+ from = 1;
133
+ }
134
+ break;
135
+ }
136
+ }
118
137
  }
119
- break;
120
- }
121
138
  }
122
- }
123
- 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]))) {
124
- if (opts.extendToOneSide !== "right" && isWhitespace(str[from - 1]) && !opts.wipeAllWhitespaceOnLeft) {
125
- from -= 1;
139
+ if (opts.extendToOneSide !== "left" &&
140
+ ((isWhitespace(str[to]) &&
141
+ (opts.wipeAllWhitespaceOnRight || isWhitespace(str[to + 1]))) ||
142
+ opts.ifRightSideIncludesThisCropItToo.includes(str[to]))) {
143
+ for (let i = to, len = str.length; i < len; i++) {
144
+ if (!opts.ifRightSideIncludesThisCropItToo.includes(str[i]) &&
145
+ ((str[i] && str[i].trim()) || str[i] === undefined)) {
146
+ if (opts.wipeAllWhitespaceOnRight ||
147
+ opts.ifRightSideIncludesThisCropItToo.includes(str[i - 1])) {
148
+ to = i;
149
+ }
150
+ else {
151
+ to = i - 1;
152
+ }
153
+ break;
154
+ }
155
+ }
156
+ }
157
+ if ((opts.extendToOneSide !== "right" &&
158
+ isStr(opts.ifLeftSideIncludesThisThenCropTightly) &&
159
+ opts.ifLeftSideIncludesThisThenCropTightly &&
160
+ ((str[from - 2] &&
161
+ opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 2])) ||
162
+ (str[from - 1] &&
163
+ opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 1])))) ||
164
+ (opts.extendToOneSide !== "left" &&
165
+ isStr(opts.ifRightSideIncludesThisThenCropTightly) &&
166
+ opts.ifRightSideIncludesThisThenCropTightly &&
167
+ ((str[to + 1] &&
168
+ opts.ifRightSideIncludesThisThenCropTightly.includes(str[to + 1])) ||
169
+ (str[to] &&
170
+ opts.ifRightSideIncludesThisThenCropTightly.includes(str[to]))))) {
171
+ if (opts.extendToOneSide !== "right" &&
172
+ isWhitespace(str[from - 1]) &&
173
+ !opts.wipeAllWhitespaceOnLeft) {
174
+ from -= 1;
175
+ }
176
+ if (opts.extendToOneSide !== "left" &&
177
+ isWhitespace(str[to]) &&
178
+ !opts.wipeAllWhitespaceOnRight) {
179
+ to += 1;
180
+ }
126
181
  }
127
- if (opts.extendToOneSide !== "left" && isWhitespace(str[to]) && !opts.wipeAllWhitespaceOnRight) {
128
- to += 1;
182
+ if (opts.addSingleSpaceToPreventAccidentalConcatenation &&
183
+ str[from - 1] &&
184
+ str[from - 1].trim() &&
185
+ str[to] &&
186
+ str[to].trim() &&
187
+ ((!opts.ifLeftSideIncludesThisThenCropTightly &&
188
+ !opts.ifRightSideIncludesThisThenCropTightly) ||
189
+ !((!opts.ifLeftSideIncludesThisThenCropTightly ||
190
+ opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 1])) &&
191
+ (!opts.ifRightSideIncludesThisThenCropTightly ||
192
+ (str[to] &&
193
+ opts.ifRightSideIncludesThisThenCropTightly.includes(str[to]))))) &&
194
+ (letterOrDigit.test(str[from - 1]) || letterOrDigit.test(str[to]))) {
195
+ return [from, to, " "];
129
196
  }
130
- }
131
- 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]))) {
132
- return [from, to, " "];
133
- }
134
- return [from, to];
197
+ return [from, to];
135
198
  }
136
199
 
137
200
  export { defaults, expander, version };
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @name string-range-expander
3
3
  * @fileoverview Expands string index ranges within whitespace boundaries until letters are met
4
- * @version 3.0.2
4
+ * @version 3.0.6
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
- !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.2",Object.defineProperty(e,"__esModule",{value:!0})}));
10
+ !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.6",Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-range-expander",
3
- "version": "3.0.2",
3
+ "version": "3.0.6",
4
4
  "description": "Expands string index ranges within whitespace boundaries until letters are met",
5
5
  "keywords": [
6
6
  "expand",
@@ -33,9 +33,10 @@
33
33
  "types": "types/index.d.ts",
34
34
  "scripts": {
35
35
  "build": "rollup -c",
36
- "esbuild": "node '../../scripts/esbuild.js'",
37
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
38
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
36
+ "build:esbuild": "node '../../scripts/esbuild.js'",
37
+ "build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
38
+ "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
39
+ "clean_types": "../../scripts/cleanTypes.js",
39
40
  "dev": "rollup -c --dev",
40
41
  "devunittest": "npm run dev && tap --only -R 'base'",
41
42
  "format": "npm run lect && npm run prettier && npm run lint",
@@ -45,20 +46,15 @@
45
46
  "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
46
47
  "republish": "npm publish || :",
47
48
  "tap": "tap",
48
- "tsc": "tsc",
49
49
  "pretest": "npm run build",
50
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
50
+ "test": "npm run test:ci && npm run perf",
51
+ "test:ci": "npm run unittest && npm run test:examples && npm run format",
51
52
  "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
52
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf",
53
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
54
- "clean_types": "../../scripts/cleanTypes.js"
53
+ "tsc": "tsc",
54
+ "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
55
55
  },
56
56
  "tap": {
57
57
  "check-coverage": false,
58
- "coverage-report": [
59
- "json-summary",
60
- "text"
61
- ],
62
58
  "node-arg": [
63
59
  "--no-warnings",
64
60
  "--experimental-loader",
@@ -78,47 +74,47 @@
78
74
  }
79
75
  },
80
76
  "dependencies": {
81
- "@babel/runtime": "^7.15.4"
77
+ "@babel/runtime": "^7.16.3"
82
78
  },
83
79
  "devDependencies": {
84
- "@babel/cli": "^7.15.4",
85
- "@babel/core": "^7.15.5",
86
- "@babel/node": "^7.15.4",
87
- "@babel/plugin-external-helpers": "^7.14.5",
88
- "@babel/plugin-proposal-class-properties": "^7.14.5",
89
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
90
- "@babel/plugin-proposal-object-rest-spread": "^7.15.6",
91
- "@babel/plugin-proposal-optional-chaining": "^7.14.5",
92
- "@babel/plugin-transform-runtime": "^7.15.0",
93
- "@babel/preset-env": "^7.15.6",
94
- "@babel/preset-typescript": "^7.15.0",
95
- "@babel/register": "^7.15.3",
80
+ "@babel/cli": "^7.16.0",
81
+ "@babel/core": "^7.16.0",
82
+ "@babel/node": "^7.16.0",
83
+ "@babel/plugin-external-helpers": "^7.16.0",
84
+ "@babel/plugin-proposal-class-properties": "^7.16.0",
85
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
86
+ "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
87
+ "@babel/plugin-proposal-optional-chaining": "^7.16.0",
88
+ "@babel/plugin-transform-runtime": "^7.16.4",
89
+ "@babel/preset-env": "^7.16.4",
90
+ "@babel/preset-typescript": "^7.16.0",
91
+ "@babel/register": "^7.16.0",
96
92
  "@istanbuljs/esm-loader-hook": "^0.1.2",
97
93
  "@rollup/plugin-babel": "^5.3.0",
98
- "@rollup/plugin-commonjs": "^20.0.0",
94
+ "@rollup/plugin-commonjs": "^21.0.1",
99
95
  "@rollup/plugin-json": "^4.1.0",
100
- "@rollup/plugin-node-resolve": "^13.0.4",
96
+ "@rollup/plugin-node-resolve": "^13.0.6",
101
97
  "@rollup/plugin-strip": "^2.1.0",
102
- "@rollup/plugin-typescript": "^8.2.5",
103
- "@types/node": "^16.9.1",
98
+ "@rollup/plugin-typescript": "^8.3.0",
99
+ "@types/node": "^16.11.9",
104
100
  "@types/tap": "^15.0.5",
105
- "@typescript-eslint/eslint-plugin": "^4.31.0",
106
- "@typescript-eslint/parser": "^4.31.0",
107
- "core-js": "^3.17.3",
101
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
102
+ "@typescript-eslint/parser": "^5.4.0",
103
+ "core-js": "^3.19.1",
108
104
  "cross-env": "^7.0.3",
109
- "eslint": "^7.32.0",
110
- "lect": "^0.18.2",
111
- "rollup": "^2.56.3",
105
+ "eslint": "^8.3.0",
106
+ "lect": "^0.18.6",
107
+ "rollup": "^2.60.0",
112
108
  "rollup-plugin-ascii": "^0.0.3",
113
109
  "rollup-plugin-banner": "^0.2.1",
114
110
  "rollup-plugin-cleanup": "^3.2.1",
115
- "rollup-plugin-dts": "^4.0.0",
111
+ "rollup-plugin-dts": "^4.0.1",
116
112
  "rollup-plugin-terser": "^7.0.2",
117
- "tap": "^15.0.9",
113
+ "tap": "^15.1.2",
118
114
  "tslib": "^2.3.1",
119
- "typescript": "^4.4.3"
115
+ "typescript": "^4.5.2"
120
116
  },
121
117
  "engines": {
122
- "node": ">=12"
118
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
123
119
  }
124
120
  }