Skip to content

Commit

Permalink
Merge pull request #51 from takanotume24/fix/#37
Browse files Browse the repository at this point in the history
Fix/#37
  • Loading branch information
takanotume24 authored Feb 15, 2024
2 parents c77ac00 + 09650b1 commit 0b9310c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/lib/format_and_split_text_Into_columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ export function formatAndSplitTextIntoColumns(
[/-\n/g, ''], // Ensure hyphen followed by newline is completely removed
[/\n/g, " "], // Replaces newlines with spaces
[/- /g, ""], // Removes hyphens followed by a space
[RegExp(`Fig${dummy}`, "g"), "Fig. "], // Formats abbreviation for "Figure"
[RegExp(`Figs${dummy}`, "g"), "Figs. "], // Formats abbreviation for "Figures"
[RegExp(`No${dummy}`, "g"), "No. "], // Formats abbreviation for "Number"
[RegExp(`Prof${dummy}`, "g"), "Prof. "], // Formats abbreviation for "Professor"
[RegExp(`Eq${dummy}`, "g"), "Eq. "], // Formats abbreviation for "Equation"
[RegExp(`eq${dummy}`, "g"), "eq. "], // Formats abbreviation for "Equation"
[RegExp(`et al${dummy}`, "g"), "et al. "], // Formats "et al."
[RegExp(`Dr${dummy}`, "g"), "Dr. "], // Formats abbreviation for "Doctor"
[RegExp(`e\.g${dummy}`, "g"), "e.g. "], // Formats "e.g."
[RegExp(`i\.e${dummy}`, "g"), "i.e. "], // Formats "i.e."
[RegExp(`etc${dummy}`, "g"), "etc. "], // Formats "etc."
[RegExp(`Sec${dummy}`, "g"), "Sec. "], // Formats abbreviation for "Section"
[RegExp(`Sect${dummy}`, "g"), "Sect. "], // Formats abbreviation for "Section"
[RegExp(`Section${dummy}`, "g"), "Section. "], // Formats abbreviation for "Section"
[RegExp(`vs${dummy}`, "g"), "vs. "], // Formats abbreviation for "vs."
[RegExp(`2\.4 GHz`, "g"), "2.4GHz"], // Formats specific frequency value
[RegExp(`I${dummy}`, "g"), "I. "],
[RegExp(`II${dummy}`, "g"), "II. "],
[RegExp(`III${dummy}`, "g"), "III. "],
[RegExp(`IV${dummy}`, "g"), "IV. "],
[RegExp(`V${dummy}`, "g"), "V. "],
[RegExp(`VI${dummy}`, "g"), "VI. "],
[RegExp(`VII${dummy}`, "g"), "VII. "],
[RegExp(`VIII${dummy}`, "g"), "VIII. "],
[RegExp(`IX${dummy}`, "g"), "IX. "],
[RegExp(`X${dummy}`, "g"), "X. "],
[RegExp(String.raw`Fig${dummy}`, "g"), "Fig. "], // Formats abbreviation for "Figure"
[RegExp(String.raw`Figs${dummy}`, "g"), "Figs. "], // Formats abbreviation for "Figures"
[RegExp(String.raw`No${dummy}`, "g"), "No. "], // Formats abbreviation for "Number"
[RegExp(String.raw`Prof${dummy}`, "g"), "Prof. "], // Formats abbreviation for "Professor"
[RegExp(String.raw`Eq${dummy}`, "g"), "Eq. "], // Formats abbreviation for "Equation"
[RegExp(String.raw`eq${dummy}`, "g"), "eq. "], // Formats abbreviation for "Equation"
[RegExp(String.raw`et al${dummy}`, "g"), "et al. "], // Formats "et al."
[RegExp(String.raw`Dr${dummy}`, "g"), "Dr. "], // Formats abbreviation for "Doctor"
[RegExp(String.raw`e\.g${dummy}`, "g"), "e.g. "], // Formats "e.g."
[RegExp(String.raw`i\.e${dummy}`, "g"), "i.e. "], // Formats "i.e."
[RegExp(String.raw`etc${dummy}`, "g"), "etc. "], // Formats "etc."
[RegExp(String.raw`Sec${dummy}`, "g"), "Sec. "], // Formats abbreviation for "Section"
[RegExp(String.raw`Sect${dummy}`, "g"), "Sect. "], // Formats abbreviation for "Section"
[RegExp(String.raw`Section${dummy}`, "g"), "Section. "], // Formats abbreviation for "Section"
[RegExp(String.raw`vs${dummy}`, "g"), "vs. "], // Formats abbreviation for "vs."
[RegExp(String.raw`2\.4 GHz`, "g"), "2.4GHz"], // Formats specific frequency value
[RegExp(String.raw`I${dummy}`, "g"), "I. "],
[RegExp(String.raw`II${dummy}`, "g"), "II. "],
[RegExp(String.raw`III${dummy}`, "g"), "III. "],
[RegExp(String.raw`IV${dummy}`, "g"), "IV. "],
[RegExp(String.raw`V${dummy}`, "g"), "V. "],
[RegExp(String.raw`VI${dummy}`, "g"), "VI. "],
[RegExp(String.raw`VII${dummy}`, "g"), "VII. "],
[RegExp(String.raw`VIII${dummy}`, "g"), "VIII. "],
[RegExp(String.raw`IX${dummy}`, "g"), "IX. "],
[RegExp(String.raw`X${dummy}`, "g"), "X. "],
[/\.\d+,\d+(?= [A-Z])/g, match => "[" + match + "]. "], // Formats numbers with commas
[/\.\d+-\d+(?= [A-Z])/g, match => "[" + match + "]. "], // Formats number ranges
];
Expand Down
22 changes: 22 additions & 0 deletions src/lib/test/format_and_split_text_into_columns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ describe('formatAndSplitTextIntoColumns', () => {
expect(result).toEqual(expectedResult);
});

it('should process and split text correctly [size. ]', () => {
const testString = "When shopping for clothes, it's essential to consider your body size. The small backpack comes in various colors and sizes.";
const charLimit = 10;
const expectedResult = [
["When shopping for clothes, it's essential to consider your body size."],
['The small backpack comes in various colors and sizes.']
];
const result = formatAndSplitTextIntoColumns(testString, charLimit);
expect(result).toEqual(expectedResult);
});

it('should process and split text correctly [time. ]', () => {
const testString = "All good things must come to an end, time. After this moment passes, we begin anew with lessons learned and memories cherished.";
const charLimit = 10;
const expectedResult = [
["All good things must come to an end, time."],
['After this moment passes, we begin anew with lessons learned and memories cherished.']
];
const result = formatAndSplitTextIntoColumns(testString, charLimit);
expect(result).toEqual(expectedResult);
});

it('should process and split text correctly [1.5 Hz. ]', () => {
const testString = "The gentle waves, oscillating at a frequency of 1.5 Hz, brought a calming rhythm to the serene beach. In the laboratory, we observed that the pendulum's natural frequency settled at 1.5 Hz, demonstrating a consistent pattern in its motion.";
const charLimit = 10;
Expand Down

0 comments on commit 0b9310c

Please sign in to comment.