stringweaver 1.2.1 → 1.2.3

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isArrayOf,
3
3
  isNumber,
4
- quotingStyles,
4
+ quotGetters4Instance as quotGetters,
5
5
  getStringValue,
6
6
  escapeRE,
7
7
  customMethods,
@@ -92,7 +92,7 @@ function toCamelcase(string) {
92
92
  );
93
93
  }
94
94
 
95
- function getBoundary(string) {
95
+ function getWordBoundary(string) {
96
96
  const match = [...string.matchAll(/\p{Pe}|\p{Z}/gu)].at(-1);
97
97
  return match?.index ?? string.length;
98
98
  }
@@ -106,7 +106,7 @@ function truncate(string, {at, html = false, wordBoundary = false} = {} ) {
106
106
  const subString = string.slice(0, at - 1);
107
107
  const endwith = html ? "…" : `...`;
108
108
  const boundary = wordBoundary
109
- ? getBoundary(subString)
109
+ ? getWordBoundary(subString)
110
110
  : subString.length;
111
111
 
112
112
  return (wordBoundary
@@ -134,16 +134,12 @@ function replaceWords(string, { replacements = {}, caseSensitive = false} = {})
134
134
  const cando = isArrayOf(String, replacements2Array) && caseSensitive?.constructor === Boolean;
135
135
  const modifiers = `g${!caseSensitive ? 'i' : ''}`;
136
136
 
137
- if (cando) {
138
- replacements2Array = replacements2Array.map(v => getStringValue(v)).filter(v => replacements2Array.length > 0);
137
+ if (!cando) { return string; }
139
138
 
140
- if (replacements2Array.length) {
141
- while (replacements2Array.length) {
142
- const [initial, replacement] = [replacements2Array.shift(), replacements2Array.shift()];
143
- const re = escapeRE(initial, modifiers);
144
- string = string.replace(re, replacement);
145
- }
146
- }
139
+ while (replacements2Array.length) {
140
+ const [initial, replacement] = [replacements2Array.shift(), replacements2Array.shift()];
141
+ const re = escapeRE(initial, modifiers);
142
+ string = string.replace(re, replacement);
147
143
  }
148
144
 
149
145
  return string;
@@ -197,32 +193,3 @@ function append(string, ...strings2Append) {
197
193
 
198
194
  return getStringValue(string);
199
195
  }
200
-
201
- function quotGetters(instance, wrap) {
202
- return {
203
- value: {
204
- get backtick() { return instance.enclose(...quotingStyles.backtick); },
205
- get bracket() { return instance.enclose(...quotingStyles.bracket); },
206
- get curlyDouble() { return instance.enclose(...quotingStyles.curlyDouble); },
207
- get curlyDoubleInward() { return instance.enclose(...quotingStyles.curlyDoubleInward); },
208
- get curlyDoubleEqual() { return instance.enclose(...quotingStyles.curlyDoubleEqual); },
209
- get curlyLHDoubleInward() { return instance.enclose(...quotingStyles.curlyLHDoubleInward); },
210
- get curlyLHSingle() { return instance.enclose(...quotingStyles.curlyLHSingle); },
211
- get curlyLHSingleInward() { return instance.enclose(...quotingStyles.curlyLHSingleInward); },
212
- get curlySingle() { return instance.enclose(...quotingStyles.curlySingle); },
213
- get curlySingleEqual() { return instance.enclose(...quotingStyles.curlySingleEqual); },
214
- get curlySingleInward() { return instance.enclose(...quotingStyles.curlySingleInward); },
215
- custom(start, end) { return instance.enclose(...[start, end ?? start]); },
216
- get double() { return instance.enclose(...quotingStyles.double); },
217
- get guillemets() { return instance.enclose(...quotingStyles.guillemets); },
218
- get guillemetsInward() { return instance.enclose(...quotingStyles.guillemetsInward); },
219
- get guillemetsSingle() { return instance.enclose(...quotingStyles.guillemetsSingle); },
220
- get guillemetsSingleInward() { return instance.enclose(...quotingStyles.guillemetsSingleInward); },
221
- get remove() { return wrap(`${instance.value.replace(quotingStyles.re, ``)}`); },
222
- get single() { return instance.enclose(...quotingStyles.single); },
223
- get squareBrackets() { return instance.enclose(...quotingStyles.squareBrackets); },
224
- },
225
- enumerable: false,
226
- configurable: false,
227
- };
228
- }