addEnglish

This commit is contained in:
lingdocs 2021-10-05 21:31:45 -04:00
parent a5e2e7ff5d
commit d258e45d6c
3 changed files with 19 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/pashto-inflector", "name": "@lingdocs/pashto-inflector",
"version": "1.1.1", "version": "1.1.2",
"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

@ -646,10 +646,23 @@ export function clamp(s: string, chars: number): string {
return `${s.slice(0, 20)}${s.length > 20 ? "..." : ""}`; 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.PsString>): T.ArrayOneOrMore<T.PsString>;
export function addEnglish(english: T.EnglishBlock | string, ps: T.SentenceForm): T.SentenceForm;
export function addEnglish( export function addEnglish(
english: T.EnglishBlock | string, english: T.EnglishBlock | string,
ps: T.VerbBlock | T.ImperativeBlock | T.ArrayOneOrMore<T.PsString>, ps: T.VerbBlock | T.ImperativeBlock | T.ArrayOneOrMore<T.PsString> | T.SentenceForm,
) { ): T.VerbBlock | T.ImperativeBlock | T.ArrayOneOrMore<T.PsString> | 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) { if (Array.isArray(ps[0]) && ps.length === 6) {
return mapVerbBlock((psString, i, j) => ({ return mapVerbBlock((psString, i, j) => ({
...psString, ...psString,
@ -667,7 +680,7 @@ export function addEnglish(
const line = ps as T.ArrayOneOrMore<T.PsString>; const line = ps as T.ArrayOneOrMore<T.PsString>;
return line.map((psString) => ( return line.map((psString) => (
{ ...psString, e: typeof english === "string" ? english : english[0][0] } { ...psString, e: typeof english === "string" ? english : english[0][0] }
)); )) as T.ArrayOneOrMore<T.PsString>;
} }
export function beginsWithDirectionalPronoun(ps: T.PsString): boolean { export function beginsWithDirectionalPronoun(ps: T.PsString): boolean {

View File

@ -35,6 +35,7 @@ import {
isPluralInflectionSet, isPluralInflectionSet,
isUnisexSet, isUnisexSet,
isInflectionSet, isInflectionSet,
addEnglish,
} from "./lib/p-text-helpers"; } from "./lib/p-text-helpers";
import { import {
getEnglishWord, getEnglishWord,
@ -128,6 +129,7 @@ export {
getVerbBlockPosFromPerson, getVerbBlockPosFromPerson,
personIsPlural, personIsPlural,
personGender, personGender,
addEnglish,
// protobuf helpers // protobuf helpers
readDictionary, readDictionary,
writeDictionary, writeDictionary,