ignoring ' in endsWith, but its type sketchy

This commit is contained in:
lingdocs 2021-10-17 16:07:49 -04:00
parent 31c5b3b4e8
commit c1fd83b8de
3 changed files with 13 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/pashto-inflector", "name": "@lingdocs/pashto-inflector",
"version": "1.2.4", "version": "1.2.5",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -1156,6 +1156,11 @@ test("endsWith", () => {
.toBe(true); .toBe(true);
expect(endsWith({ p: ["ډ", "د"] }, { p: "چت", f: "chat" })) expect(endsWith({ p: ["ډ", "د"] }, { p: "چت", f: "chat" }))
.toBe(false); .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 // ability to curry
expect(endsWith({ p: "ی", f: "ey" })({ p: "سړی", f: "saRéy" })) expect(endsWith({ p: "ی", f: "ey" })({ p: "سړی", f: "saRéy" }))
.toBe(true); .toBe(true);

View File

@ -995,12 +995,16 @@ export function endsWith(
if ("f" in ending && Array.isArray(ending.f)) { if ("f" in ending && Array.isArray(ending.f)) {
return ending.f.some(e => endsWith({ f: e }, ps)); 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 ( return (
(("p" in ending) ? ps.p.slice(-ending.p.length) === ending.p : true) (("p" in ending) ? ps.p.slice(-ending.p.length) === ending.p : true)
&& &&
(("f" in ending) ? ((fEnd) ?
((matchAccent ? f.slice(-ending.f.length) : removeAccents(f.slice(-ending.f.length))) === ending.f) ((matchAccent ? f.slice(-fEnd.length) : removeAccents(f.slice(-fEnd.length))) === fEnd)
: true) : true)
); );
} }