@arsedizioni/ars-utils 21.2.324 → 21.2.326
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/fesm2022/arsedizioni-ars-utils-clipper.common.mjs.map +1 -1
- package/fesm2022/arsedizioni-ars-utils-clipper.ui.mjs +4 -4
- package/fesm2022/arsedizioni-ars-utils-clipper.ui.mjs.map +1 -1
- package/fesm2022/arsedizioni-ars-utils-core.mjs +37 -0
- package/fesm2022/arsedizioni-ars-utils-core.mjs.map +1 -1
- package/package.json +1 -1
- package/types/arsedizioni-ars-utils-clipper.common.d.ts +2 -2
- package/types/arsedizioni-ars-utils-clipper.ui.d.ts +1 -1
- package/types/arsedizioni-ars-utils-core.d.ts +6 -0
- package/types/arsedizioni-ars-utils-ui.application.d.ts +1 -1
|
@@ -311,6 +311,43 @@ class SystemUtils {
|
|
|
311
311
|
}
|
|
312
312
|
return items[0];
|
|
313
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Normalize a string by converting it to lowercase and removing extra spaces, with special handling for acronyms and camelCase.
|
|
316
|
+
* @param s : the string to normalize
|
|
317
|
+
* @returns : The normalized string, or `undefined` if the input is falsy.
|
|
318
|
+
*/
|
|
319
|
+
static normalize(s) {
|
|
320
|
+
if (!s)
|
|
321
|
+
return s;
|
|
322
|
+
return s
|
|
323
|
+
.split(' ')
|
|
324
|
+
.map((word, wordIndex) => {
|
|
325
|
+
if (!word)
|
|
326
|
+
return word;
|
|
327
|
+
// If the word is all uppercase and contains at least one letter, we assume it's an acronym and leave it as is
|
|
328
|
+
if (word === word.toUpperCase() && /[A-Z]/.test(word)) {
|
|
329
|
+
return word;
|
|
330
|
+
}
|
|
331
|
+
// Otherwise, convert to lowercase letter by letter
|
|
332
|
+
const chars = word.split('');
|
|
333
|
+
return chars
|
|
334
|
+
.map((char, charIndex) => {
|
|
335
|
+
if (charIndex === 0 && wordIndex === 0) {
|
|
336
|
+
// First letter of the first word:
|
|
337
|
+
// remains uppercase only if the first 2 letters are both uppercase
|
|
338
|
+
const secondChar = chars[1] ?? '';
|
|
339
|
+
const keepUppercase = char === char.toUpperCase() &&
|
|
340
|
+
secondChar === secondChar.toUpperCase() &&
|
|
341
|
+
/[A-Z]/.test(char) &&
|
|
342
|
+
/[A-Z]/.test(secondChar);
|
|
343
|
+
return keepUppercase ? char : char.toLowerCase();
|
|
344
|
+
}
|
|
345
|
+
return char.toLowerCase();
|
|
346
|
+
})
|
|
347
|
+
.join('');
|
|
348
|
+
})
|
|
349
|
+
.join(' ');
|
|
350
|
+
}
|
|
314
351
|
/**
|
|
315
352
|
* Wraps bare URLs in the given string with `<a>` anchor tags.
|
|
316
353
|
* @param s - The plain-text or HTML string to process.
|