@docaohuynh/ielts-api-utils 1.0.12 → 1.0.13
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/dist/index.js +29 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -646,9 +646,23 @@ function removeEmptyLines(str) {
|
|
|
646
646
|
}
|
|
647
647
|
// src/utils/strings/remove-string.util.ts
|
|
648
648
|
function removeWordsFromText(text, words) {
|
|
649
|
-
if (!text
|
|
649
|
+
if (!text) {
|
|
650
650
|
return text;
|
|
651
651
|
}
|
|
652
|
+
if (!words || words.length === 0) {
|
|
653
|
+
const hasWindowsLineEndings2 = text.includes(`\r
|
|
654
|
+
`);
|
|
655
|
+
if (hasWindowsLineEndings2) {
|
|
656
|
+
const lines = text.split(/\r?\n/);
|
|
657
|
+
return lines.map((line) => line.replace(/\s+/g, " ").trim()).join(`\r
|
|
658
|
+
`).trim();
|
|
659
|
+
} else {
|
|
660
|
+
const lines = text.split(`
|
|
661
|
+
`);
|
|
662
|
+
return lines.map((line) => line.replace(/\s+/g, " ").trim()).join(`
|
|
663
|
+
`).trim();
|
|
664
|
+
}
|
|
665
|
+
}
|
|
652
666
|
const escapedWords = words.map((word) => {
|
|
653
667
|
const escapedWord = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
654
668
|
const startsWithSpecialChar = /^\W/.test(word);
|
|
@@ -660,7 +674,20 @@ function removeWordsFromText(text, words) {
|
|
|
660
674
|
}
|
|
661
675
|
});
|
|
662
676
|
const regex = new RegExp(`(${escapedWords.join("|")})`, "gi");
|
|
663
|
-
|
|
677
|
+
let result = text.replace(regex, "");
|
|
678
|
+
const hasWindowsLineEndings = text.includes(`\r
|
|
679
|
+
`);
|
|
680
|
+
if (hasWindowsLineEndings) {
|
|
681
|
+
const lines = result.split(/\r?\n/);
|
|
682
|
+
result = lines.map((line) => line.replace(/\s+/g, " ").trim()).join(`\r
|
|
683
|
+
`);
|
|
684
|
+
} else {
|
|
685
|
+
const lines = result.split(`
|
|
686
|
+
`);
|
|
687
|
+
result = lines.map((line) => line.replace(/\s+/g, " ").trim()).join(`
|
|
688
|
+
`);
|
|
689
|
+
}
|
|
690
|
+
return result.trim();
|
|
664
691
|
}
|
|
665
692
|
// src/utils/decode/decode-signed.util.ts
|
|
666
693
|
function decodeSignedPayload(signedPayload) {
|