From d258e45d6c4a0fe37432c25a5d9cf6bcfc46c911 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Tue, 5 Oct 2021 21:31:45 -0400 Subject: [PATCH] addEnglish --- package.json | 2 +- src/lib/p-text-helpers.ts | 19 ++++++++++++++++--- src/library.ts | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3652040..a5b058e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.1.1", + "version": "1.1.2", "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.ts b/src/lib/p-text-helpers.ts index c8713c4..148bb00 100644 --- a/src/lib/p-text-helpers.ts +++ b/src/lib/p-text-helpers.ts @@ -646,10 +646,23 @@ export function clamp(s: string, chars: number): string { return `${s.slice(0, 20)}${s.length > 20 ? "..." : ""}`; } +export function addEnglish(english: T.EnglishBlock | string, ps: T.VerbBlock): T.VerbBlock; +export function addEnglish(english: T.EnglishBlock | string, ps: T.ImperativeBlock): T.ImperativeBlock; +export function addEnglish(english: T.EnglishBlock | string, ps: T.ArrayOneOrMore): T.ArrayOneOrMore; +export function addEnglish(english: T.EnglishBlock | string, ps: T.SentenceForm): T.SentenceForm; export function addEnglish( english: T.EnglishBlock | string, - ps: T.VerbBlock | T.ImperativeBlock | T.ArrayOneOrMore, -) { + ps: T.VerbBlock | T.ImperativeBlock | T.ArrayOneOrMore | T.SentenceForm, +): T.VerbBlock | T.ImperativeBlock | T.ArrayOneOrMore | T.SentenceForm { + if ("long" in ps) { + return { + long: addEnglish(english, ps.long), + short: addEnglish(english, ps.short), + ...ps.mini ? { + mini: addEnglish(english, ps.mini), + } : {}, + }; + } if (Array.isArray(ps[0]) && ps.length === 6) { return mapVerbBlock((psString, i, j) => ({ ...psString, @@ -667,7 +680,7 @@ export function addEnglish( const line = ps as T.ArrayOneOrMore; return line.map((psString) => ( { ...psString, e: typeof english === "string" ? english : english[0][0] } - )); + )) as T.ArrayOneOrMore; } export function beginsWithDirectionalPronoun(ps: T.PsString): boolean { diff --git a/src/library.ts b/src/library.ts index c1347b8..bdcdf0f 100644 --- a/src/library.ts +++ b/src/library.ts @@ -35,6 +35,7 @@ import { isPluralInflectionSet, isUnisexSet, isInflectionSet, + addEnglish, } from "./lib/p-text-helpers"; import { getEnglishWord, @@ -128,6 +129,7 @@ export { getVerbBlockPosFromPerson, personIsPlural, personGender, + addEnglish, // protobuf helpers readDictionary, writeDictionary,