@docaohuynh/ielts-api-utils 1.0.11 → 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 CHANGED
@@ -644,6 +644,51 @@ function removeEmptyLines(str) {
644
644
  return str.split(/\r?\n/).filter((line) => line.trim() !== "").join(`
645
645
  `);
646
646
  }
647
+ // src/utils/strings/remove-string.util.ts
648
+ function removeWordsFromText(text, words) {
649
+ if (!text) {
650
+ return text;
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
+ }
666
+ const escapedWords = words.map((word) => {
667
+ const escapedWord = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
668
+ const startsWithSpecialChar = /^\W/.test(word);
669
+ const endsWithSpecialChar = /\W$/.test(word);
670
+ if (startsWithSpecialChar || endsWithSpecialChar) {
671
+ return escapedWord;
672
+ } else {
673
+ return `\\b${escapedWord}\\b`;
674
+ }
675
+ });
676
+ const regex = new RegExp(`(${escapedWords.join("|")})`, "gi");
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();
691
+ }
647
692
  // src/utils/decode/decode-signed.util.ts
648
693
  function decodeSignedPayload(signedPayload) {
649
694
  const parts = signedPayload.split(".");
@@ -7549,6 +7594,7 @@ export {
7549
7594
  sendDeleteWithBearer,
7550
7595
  sendDelete,
7551
7596
  replaceWordInList,
7597
+ removeWordsFromText,
7552
7598
  removeEmptyLines,
7553
7599
  normalizeText,
7554
7600
  isEqual,
@@ -1,3 +1,4 @@
1
1
  export * from './split.util';
2
2
  export * from './normalize.util';
3
3
  export * from './empty-line.util';
4
+ export * from './remove-string.util';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Removes specified words from the given text
3
+ * @param text - The input text to remove words from
4
+ * @param words - Array of words to remove from the text
5
+ * @returns The text with specified words removed
6
+ */
7
+ export declare function removeWordsFromText(text: string, words: string[]): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docaohuynh/ielts-api-utils",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Utilities for IELTS API",
5
5
  "module": "index.ts",
6
6
  "main": "dist/index.js",