From c1fd83b8dea41b0d06abf7ac83b1a32aa2e4aca4 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sun, 17 Oct 2021 16:07:49 -0400 Subject: [PATCH] ignoring ' in endsWith, but its type sketchy --- package.json | 2 +- src/lib/p-text-helpers.test.ts | 5 +++++ src/lib/p-text-helpers.ts | 10 +++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index da5cc78..7c017a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.2.4", + "version": "1.2.5", "author": "lingdocs.com", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "homepage": "https://verbs.lingdocs.com", diff --git a/src/lib/p-text-helpers.test.ts b/src/lib/p-text-helpers.test.ts index 0f7ff71..d382104 100644 --- a/src/lib/p-text-helpers.test.ts +++ b/src/lib/p-text-helpers.test.ts @@ -1156,6 +1156,11 @@ test("endsWith", () => { .toBe(true); expect(endsWith({ p: ["ډ", "د"] }, { p: "چت", f: "chat" })) .toBe(false); + // ignore ' + expect(endsWith({ p: "ا", f: "aa" }, { p: "اعدا", f: "idaa'" })) + .toBe(true); + expect(endsWith({ p: "ا", f: "aa'" }, { p: "اعدا", f: "idaa" })) + .toBe(true); // ability to curry expect(endsWith({ p: "ی", f: "ey" })({ p: "سړی", f: "saRéy" })) .toBe(true); diff --git a/src/lib/p-text-helpers.ts b/src/lib/p-text-helpers.ts index 0460acc..9f8371f 100644 --- a/src/lib/p-text-helpers.ts +++ b/src/lib/p-text-helpers.ts @@ -995,12 +995,16 @@ export function endsWith( if ("f" in ending && Array.isArray(ending.f)) { return ending.f.some(e => endsWith({ f: e }, ps)); } - const f = removeFVarients(ps.f); + const f = removeFVarients(ps.f).replace(/'/g, ""); + const fEnd = "f" in ending + // @ts-ignore + ? ending.f.replace(/'/g, "") + : undefined; return ( (("p" in ending) ? ps.p.slice(-ending.p.length) === ending.p : true) && - (("f" in ending) ? - ((matchAccent ? f.slice(-ending.f.length) : removeAccents(f.slice(-ending.f.length))) === ending.f) + ((fEnd) ? + ((matchAccent ? f.slice(-fEnd.length) : removeAccents(f.slice(-fEnd.length))) === fEnd) : true) ); } \ No newline at end of file