Skip to content

Commit

Permalink
fix: #208 isPersian replacing ه wit arabic ه (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
pshaddel committed Jul 7, 2022
1 parent 8f59246 commit 15bd04e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/modules/toPersianChars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ function toPersianChars(str: string): string | undefined {
str = str.replace(/ي/g, "ی");
str = str.replace(/ك/g, "ک");
str = str.replace(/ى/g, "ی");
str = str.replace(new RegExp("ه($|[^ء-يٱ-ە])", "g"), "ە$1");
str = str.replace(new RegExp("([^ء-يٱ-ە]|$)ه", "g"), "ە$1");
str = str.replace(/ە‌/g, "ە");
str = str.replace(/ه/g, "ھ");

// NOTE: This will also undo changes to categories which is not good
// but we will undo that later
Expand Down
6 changes: 6 additions & 0 deletions test/isPersian.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { toPersianChars } from "../src";
import { isPersian, hasPersian } from "../src/modules/isPersian";

it("isPersian", () => {
Expand All @@ -17,6 +18,11 @@ it("isPersian", () => {
expect(isPersian("")).toBeFalsy();
});

it("isPersian Bug#208, shah, mahdi", () => {
expect(isPersian(toPersianChars("مهدی") as string)).toBe(true);
expect(isPersian(toPersianChars("شاه") as string)).toBe(true);
});

it("hasPersian", () => {
expect(hasPersian("این یک متن فارسی است؟")).toBeTruthy();
expect(hasPersian("هل هذا نص فارسي؟")).toBeTruthy();
Expand Down

0 comments on commit 15bd04e

Please sign in to comment.