From 61c4ab8bc775ba1299eef8eea547ecfd612ff4df Mon Sep 17 00:00:00 2001 From: adueck Date: Sat, 14 Jan 2023 18:48:35 +0500 Subject: [PATCH] more flexible concatPsString --- package-lock.json | 4 ++-- package.json | 2 +- src/components/package.json | 2 +- src/lib/package.json | 2 +- src/lib/src/p-text-helpers.ts | 38 +++++++++++++++++------------------ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4c01278..8a7c0d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pashto-inflector", - "version": "5.3.6", + "version": "5.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "pashto-inflector", - "version": "5.3.6", + "version": "5.4.0", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 47c607e..978e3e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pashto-inflector", - "version": "5.3.6", + "version": "5.4.0", "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/components/package.json b/src/components/package.json index 08e2ab3..872199b 100644 --- a/src/components/package.json +++ b/src/components/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/ps-react", - "version": "5.3.6", + "version": "5.4.0", "description": "Pashto inflector library module with React components", "main": "dist/components/library.js", "module": "dist/components/library.js", diff --git a/src/lib/package.json b/src/lib/package.json index 889ad5e..fba2bdb 100644 --- a/src/lib/package.json +++ b/src/lib/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/inflect", - "version": "5.3.6", + "version": "5.4.0", "description": "Pashto inflector library", "main": "dist/index.js", "types": "dist/lib/library.d.ts", diff --git a/src/lib/src/p-text-helpers.ts b/src/lib/src/p-text-helpers.ts index ae7d822..fc58c1e 100644 --- a/src/lib/src/p-text-helpers.ts +++ b/src/lib/src/p-text-helpers.ts @@ -30,18 +30,18 @@ import { makePsString, removeFVarients } from "./accent-and-ps-utils"; * * @param items */ -export function concatPsString(...items: Array): T.PsString; -export function concatPsString(...items: Array | " " | "">): T.LengthOptions; -export function concatPsString(...items: Array | T.OptionalPersonInflections> | " " | "">): T.OptionalPersonInflections>; -export function concatPsString(...items: Array | " " | "">): T.FullForm; -export function concatPsString(...items: Array | T.FullForm | " " | "">): T.FullForm { - const hasPersonInflections = items.some((x) => ((typeof x !== "string") && ("mascSing" in x))); +export function concatPsString(...items: Array): T.PsString; +export function concatPsString(...items: Array | string | undefined>): T.LengthOptions; +export function concatPsString(...items: Array | T.OptionalPersonInflections> | string | undefined>): T.OptionalPersonInflections>; +export function concatPsString(...items: Array | string | undefined>): T.FullForm; +export function concatPsString(...items: Array | T.FullForm | string | undefined>): T.FullForm { + const hasPersonInflections = items.some((x) => (x && (typeof x !== "string") && ("mascSing" in x))); if (hasPersonInflections) { const forceInflection = ( - arr: Array | " " | "">, + arr: Array | string | undefined>, inflection: T.PersonInflectionsField, - ): Array | " " | ""> => ( - arr.map((element) => (typeof element !== "string" && "mascSing" in element) + ): Array | string | undefined> => ( + arr.map((element) => (element && typeof element !== "string" && "mascSing" in element) ? element[inflection] : element ) @@ -53,14 +53,14 @@ export function concatPsString(...items: Array)[]; + const itemsWOutPersInfs = items as (string | T.SingleOrLengthOpts)[]; const hasLengthOptions = itemsWOutPersInfs.some((x) => (typeof x !== "string") && ("long" in x)); if (hasLengthOptions) { const forceLength = ( - arr: Array | " ">, + arr: Array | string | undefined>, length: "long" | "short" | "mini", - ): Array => ( - arr.map((element) => (element !== " " && "long" in element) + ): Array => ( + arr.map((element) => (element && typeof element !== "string" && "long" in element) ? element[length] || element.short : element ) @@ -68,17 +68,17 @@ export function concatPsString(...items: Array typeof x !== "string" && ("mini" in x)); return { ...hasMini ? { - mini: concatPsString(...forceLength(items as Array | " ">, "mini")), + mini: concatPsString(...forceLength(items as Array | string | undefined>, "mini")), } : {}, - short: concatPsString(...forceLength(items as Array | " ">, "short")), - long: concatPsString(...forceLength(items as Array | " ">, "long")), + short: concatPsString(...forceLength(items as Array | string | undefined>, "short")), + long: concatPsString(...forceLength(items as Array | string | undefined>, "long")), }; } - const itemsWOutLengthOptions = itemsWOutPersInfs as ("" | " " | T.PsString)[]; + const itemsWOutLengthOptions = itemsWOutPersInfs as (string | undefined | T.PsString)[]; const concatField = (k: T.PsStringField): string => ( itemsWOutLengthOptions.map((item): string => { - if (item === " ") return " "; - if (item === "") return ""; + if (item === undefined) return ""; + if (typeof item === "string") return item; return item[k]; }).join("") );