From 7b5242d1652e56b0cbde9da31539bbcd521a10eb Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sat, 16 Oct 2021 12:35:23 -0400 Subject: [PATCH] improve endsWith --- package.json | 2 +- src/lib/p-text-helpers.test.ts | 2 ++ src/lib/p-text-helpers.ts | 8 +++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 272cafe..b188b4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.2.2", + "version": "1.2.3", "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 a4c7236..0f7ff71 100644 --- a/src/lib/p-text-helpers.test.ts +++ b/src/lib/p-text-helpers.test.ts @@ -1152,6 +1152,8 @@ test("endsWith", () => { .toBe(false); expect(endsWith({ p: ["د", "ت"] }, { p: "چت", f: "chat" })) .toBe(true); + expect(endsWith([{ p: "ای", f: "aay" }, { p: ["د", "ت"] }], { p: "چت", f: "chat" })) + .toBe(true); expect(endsWith({ p: ["ډ", "د"] }, { p: "چت", f: "chat" })) .toBe(false); // ability to curry diff --git a/src/lib/p-text-helpers.ts b/src/lib/p-text-helpers.ts index b23c460..0460acc 100644 --- a/src/lib/p-text-helpers.ts +++ b/src/lib/p-text-helpers.ts @@ -957,6 +957,8 @@ export function isPluralInflections(inf: T.PluralInflections | T.Inflections): i return inf.fem.length === 2; } + +// TODO: make this usable with things like endsWith([{ f: ["t", "b"] } | { ps: "ای", f: "aay" }]) /** * determines if ps ends with a given ending, or one of an array of given endings * (can be accent sensitive or not) @@ -966,16 +968,16 @@ export function isPluralInflections(inf: T.PluralInflections | T.Inflections): i * */ export function endsWith( - ending: T.PsString | T.PsString[] | { p: string | string[] } | { f: string | string[] }, + ending: (T.PsString | { p: string | string[] } | { f: string | string[] }) | (T.PsString | { p: string | string[] } | { f: string | string[] })[], ps?: boolean, ): (ps: T.PsString) => boolean; export function endsWith( - ending: T.PsString | T.PsString[] | { p: string | string[] } | { f: string | string[] }, + ending: (T.PsString | { p: string | string[] } | { f: string | string[] }) | (T.PsString | { p: string | string[] } | { f: string | string[] })[], ps: T.PsString, matchAccent?: boolean, ): boolean; export function endsWith( - ending: T.PsString | T.PsString[] | { p: string | string[] } | { f: string | string[] }, + ending: (T.PsString | { p: string | string[] } | { f: string | string[] }) | (T.PsString | { p: string | string[] } | { f: string | string[] })[], ps: T.PsString | undefined | boolean, matchAccent?: boolean | undefined, ): boolean | ((ps: T.PsString) => boolean) {