@sankhyalabs/core 5.15.0 → 5.20.0-dev.1
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/.docs/classes/ArrayUtils.md +133 -3
- package/.docs/classes/JSUtils.md +25 -0
- package/.docs/classes/ObjectUtils.md +26 -0
- package/.docs/classes/SearchUtils.md +43 -0
- package/.docs/classes/StringUtils.md +177 -23
- package/.docs/modules.md +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/ArrayUtils.d.ts +39 -0
- package/dist/utils/ArrayUtils.js +69 -0
- package/dist/utils/ArrayUtils.js.map +1 -1
- package/dist/utils/JSUtils.d.ts +7 -0
- package/dist/utils/JSUtils.js +16 -0
- package/dist/utils/JSUtils.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +8 -0
- package/dist/utils/ObjectUtils.js +10 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/SearchUtils.d.ts +6 -0
- package/dist/utils/SearchUtils.js +17 -0
- package/dist/utils/SearchUtils.js.map +1 -0
- package/dist/utils/StringUtils.d.ts +7 -0
- package/dist/utils/StringUtils.js +97 -0
- package/dist/utils/StringUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/utils/ArrayUtils.ts +73 -0
- package/src/utils/JSUtils.ts +18 -0
- package/src/utils/ObjectUtils.ts +11 -0
- package/src/utils/SearchUtils.ts +18 -0
- package/src/utils/StringUtils.ts +124 -0
package/src/utils/StringUtils.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { v4 as uuid } from "uuid";
|
|
2
|
+
import ArrayUtils from "./ArrayUtils.js";
|
|
3
|
+
import { JSUtils } from "./JSUtils.js";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* `StringUtils`: Utilizado para manipulação de Strings.
|
|
@@ -414,4 +416,126 @@ export class StringUtils {
|
|
|
414
416
|
static getOppositeCase(original: string): string {
|
|
415
417
|
return this.isLowerCase(original) ? original.toUpperCase() : original.toLowerCase()
|
|
416
418
|
}
|
|
419
|
+
|
|
420
|
+
public static replaceToSpace(source: string, replaceList: string[] = []) {
|
|
421
|
+
if (source == undefined) {
|
|
422
|
+
return source;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
replaceList.forEach((word: string) => {
|
|
426
|
+
const wordAux = new RegExp(word, 'g');
|
|
427
|
+
let whiteSpace = '';
|
|
428
|
+
for (let i = 0; i < word.length; i++) {
|
|
429
|
+
whiteSpace += ' ';
|
|
430
|
+
}
|
|
431
|
+
source = String(source).replace(wordAux, whiteSpace);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
return source;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
public static replaceAccentuatedCharsHtmlEntities(source: string) {
|
|
438
|
+
const charsWithoutAccentuation = "AEIOU_AO_AEIOU_AEIOU_U_C_aeiou_ao_aeiou_aeiou_u_c";
|
|
439
|
+
if (source == undefined) {
|
|
440
|
+
return source;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const replaceList = ['&', '<', '>', '"'];
|
|
444
|
+
const sourceAux = StringUtils.replaceToSpace(source, replaceList);
|
|
445
|
+
|
|
446
|
+
return sourceAux.replace(/[^\w ]/g, (char: string) => {
|
|
447
|
+
let index = charsWithoutAccentuation.indexOf(char);
|
|
448
|
+
|
|
449
|
+
if (index > -1) {
|
|
450
|
+
char = charsWithoutAccentuation.charAt(index);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return char || '';
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
public static getSpecialCharacters(str: string) {
|
|
458
|
+
const specialCharsRegex = /[[.\-\$\+\*,_\&\(\)%\/\\#@!:\|\=\'\"]/gmi;
|
|
459
|
+
let match: any;
|
|
460
|
+
let charList = [];
|
|
461
|
+
while ((match = specialCharsRegex.exec(str))) {
|
|
462
|
+
charList.push(str[match.index]);
|
|
463
|
+
}
|
|
464
|
+
return charList;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
public static replaceAll(str: string, strFrom: string, strTo: string) {
|
|
468
|
+
let pos = (str != undefined ? str : '').indexOf(strFrom);
|
|
469
|
+
while (pos > -1) {
|
|
470
|
+
str = str.replace(strFrom, strTo);
|
|
471
|
+
pos = str.indexOf(strFrom);
|
|
472
|
+
}
|
|
473
|
+
return (str);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
public static removeSpecialCharacters(str: string) {
|
|
477
|
+
let specialChars = StringUtils.getSpecialCharacters(str);
|
|
478
|
+
specialChars.forEach((ch: string) => {
|
|
479
|
+
str = StringUtils.replaceAll(str, ch, '');
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
return str;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
public static getArgumentNumber(argument: String) {
|
|
486
|
+
return Number(argument || undefined);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
public static highlightValue(argument: String, matchFields: any, value: string, fieldMD: any, forceMatch: boolean) {
|
|
490
|
+
const startHighlightTag = "<span class='card-item__highlight'>";
|
|
491
|
+
const endHighlightTag = "</span>";
|
|
492
|
+
let valueAux = JSUtils.replaceHtmlEntities(value);
|
|
493
|
+
|
|
494
|
+
if (argument && (forceMatch || ArrayUtils.isIn(matchFields, fieldMD.fieldName))) {
|
|
495
|
+
const argumentNumber = StringUtils.getArgumentNumber(argument);
|
|
496
|
+
|
|
497
|
+
let replacements = (isNaN(argumentNumber) ? argument : argumentNumber.toString()).split(/%|,|\s+/);
|
|
498
|
+
let lastMatchIndex = 0;
|
|
499
|
+
let cleanText = StringUtils.replaceAccentuatedCharsHtmlEntities(valueAux);
|
|
500
|
+
|
|
501
|
+
replacements.forEach((r: string) => {
|
|
502
|
+
if (r) {
|
|
503
|
+
r = StringUtils.replaceAccentuatedCharsHtmlEntities(r);
|
|
504
|
+
|
|
505
|
+
let specialChars = StringUtils.getSpecialCharacters(r);
|
|
506
|
+
|
|
507
|
+
if (specialChars != undefined && specialChars.length > 0) {
|
|
508
|
+
r = StringUtils.removeSpecialCharacters(r);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (fieldMD.mask || fieldMD.uiType === 'CGC_CPF' || fieldMD.uiType === 'Phone') {
|
|
512
|
+
//Fazemos isso para descondirerar os caracteres especiais de formatação da string
|
|
513
|
+
r = r.split('').join('\\.?\\-?\\/?\\(?\\)?');
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
let regex = new RegExp(r, "ig");
|
|
517
|
+
regex.lastIndex = lastMatchIndex;
|
|
518
|
+
let match = regex.exec(cleanText);
|
|
519
|
+
|
|
520
|
+
if (match && match.length > 0) {
|
|
521
|
+
lastMatchIndex = match.index;
|
|
522
|
+
let sizeMatch = match[0].length;
|
|
523
|
+
|
|
524
|
+
let txtToColor = valueAux.substring(lastMatchIndex, lastMatchIndex + sizeMatch);
|
|
525
|
+
let txtColored = txtToColor?.trim() ? startHighlightTag + txtToColor + endHighlightTag : '';
|
|
526
|
+
|
|
527
|
+
let start = valueAux.substring(0, lastMatchIndex);
|
|
528
|
+
let end = valueAux.substring(lastMatchIndex + sizeMatch);
|
|
529
|
+
|
|
530
|
+
valueAux = start + txtColored + end;
|
|
531
|
+
lastMatchIndex = lastMatchIndex + txtColored.length;
|
|
532
|
+
|
|
533
|
+
cleanText = StringUtils.replaceAccentuatedCharsHtmlEntities(valueAux);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
return valueAux;
|
|
540
|
+
}
|
|
417
541
|
}
|