better endsWith
This commit is contained in:
parent
e7e773c825
commit
7a61b27b41
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lingdocs/pashto-inflector",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"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",
|
||||
|
|
|
@ -1138,4 +1138,20 @@ test("endsWith", () => {
|
|||
.toBe(true);
|
||||
expect(endsWith({ p: "چای", f: "chaay" }, [{ p: "وی", f: "ooy" }, { p: "ای", f: "aay" }]))
|
||||
.toBe(true);
|
||||
expect(endsWith({ p: "ویده", f: "weedú" }, { p: "ه"} ))
|
||||
.toBe(true);
|
||||
expect(endsWith({ p: "ویده", f: "weedú" }, { p: "ت"} ))
|
||||
.toBe(false);
|
||||
expect(endsWith({ p: "ویده", f: "weedú" }, { f: "u" } ))
|
||||
.toBe(true);
|
||||
expect(endsWith({ p: "ویده", f: "weedú" }, { f: "u" }, true))
|
||||
.toBe(false);
|
||||
expect(endsWith({ p: "چت", f: "chat" }, { f: ["d", "t"] }))
|
||||
.toBe(true);
|
||||
expect(endsWith({ p: "چت", f: "chat" }, { f: ["d", "D"] }))
|
||||
.toBe(false);
|
||||
expect(endsWith({ p: "چت", f: "chat" }, { p: ["د", "ت"] }))
|
||||
.toBe(true);
|
||||
expect(endsWith({ p: "چت", f: "chat" }, { p: ["ډ", "د"] }))
|
||||
.toBe(false);
|
||||
});
|
|
@ -966,14 +966,26 @@ export function isPluralInflections(inf: T.PluralInflections | T.Inflections): i
|
|||
* @param matchAccent - true if you want it to be accent-sensitive
|
||||
* @returns
|
||||
*/
|
||||
export function endsWith(ps: T.PsString, ending: T.PsString | T.PsString[], matchAccent?: boolean): boolean {
|
||||
export function endsWith(
|
||||
ps: T.PsString,
|
||||
ending: T.PsString | T.PsString[] | { p: string | string[] } | { f: string | string[] },
|
||||
matchAccent?: boolean,
|
||||
): boolean {
|
||||
if (Array.isArray(ending)) {
|
||||
return ending.some(e => endsWith(ps, e));
|
||||
}
|
||||
if ("p" in ending && Array.isArray(ending.p)) {
|
||||
return ending.p.some(e => endsWith(ps, { p: e }));
|
||||
}
|
||||
if ("f" in ending && Array.isArray(ending.f)) {
|
||||
return ending.f.some(e => endsWith(ps, { f: e }));
|
||||
}
|
||||
const f = removeFVarients(ps.f);
|
||||
return (
|
||||
ps.p.slice(-ending.p.length) === ending.p
|
||||
(("p" in ending) ? ps.p.slice(-ending.p.length) === ending.p : true)
|
||||
&&
|
||||
(matchAccent ? f.slice(-ending.f.length) : removeAccents(f.slice(-ending.f.length))) === ending.f
|
||||
(("f" in ending) ?
|
||||
((matchAccent ? f.slice(-ending.f.length) : removeAccents(f.slice(-ending.f.length))) === ending.f)
|
||||
: true)
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue