more flexible concatPsString
This commit is contained in:
parent
e2e1cb6600
commit
61c4ab8bc7
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "pashto-inflector",
|
"name": "pashto-inflector",
|
||||||
"version": "5.3.6",
|
"version": "5.4.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "pashto-inflector",
|
"name": "pashto-inflector",
|
||||||
"version": "5.3.6",
|
"version": "5.4.0",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "pashto-inflector",
|
"name": "pashto-inflector",
|
||||||
"version": "5.3.6",
|
"version": "5.4.0",
|
||||||
"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",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lingdocs/ps-react",
|
"name": "@lingdocs/ps-react",
|
||||||
"version": "5.3.6",
|
"version": "5.4.0",
|
||||||
"description": "Pashto inflector library module with React components",
|
"description": "Pashto inflector library module with React components",
|
||||||
"main": "dist/components/library.js",
|
"main": "dist/components/library.js",
|
||||||
"module": "dist/components/library.js",
|
"module": "dist/components/library.js",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lingdocs/inflect",
|
"name": "@lingdocs/inflect",
|
||||||
"version": "5.3.6",
|
"version": "5.4.0",
|
||||||
"description": "Pashto inflector library",
|
"description": "Pashto inflector library",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/lib/library.d.ts",
|
"types": "dist/lib/library.d.ts",
|
||||||
|
|
|
@ -30,18 +30,18 @@ import { makePsString, removeFVarients } from "./accent-and-ps-utils";
|
||||||
*
|
*
|
||||||
* @param items
|
* @param items
|
||||||
*/
|
*/
|
||||||
export function concatPsString(...items: Array<T.PsString | " " | "">): T.PsString;
|
export function concatPsString(...items: Array<T.PsString | string | undefined>): T.PsString;
|
||||||
export function concatPsString(...items: Array<T.PsString | T.LengthOptions<T.PsString> | " " | "">): T.LengthOptions<T.PsString>;
|
export function concatPsString(...items: Array<T.PsString | T.LengthOptions<T.PsString> | string | undefined>): T.LengthOptions<T.PsString>;
|
||||||
export function concatPsString(...items: Array<T.PsString | T.LengthOptions<T.PsString> | T.OptionalPersonInflections<T.LengthOptions<T.PsString>> | " " | "">): T.OptionalPersonInflections<T.LengthOptions<T.PsString>>;
|
export function concatPsString(...items: Array<T.PsString | T.LengthOptions<T.PsString> | T.OptionalPersonInflections<T.LengthOptions<T.PsString>> | string | undefined>): T.OptionalPersonInflections<T.LengthOptions<T.PsString>>;
|
||||||
export function concatPsString(...items: Array<T.PsString | T.FullForm<T.PsString> | " " | "">): T.FullForm<T.PsString>;
|
export function concatPsString(...items: Array<T.PsString | T.FullForm<T.PsString> | string | undefined>): T.FullForm<T.PsString>;
|
||||||
export function concatPsString(...items: Array<T.PsString | T.LengthOptions<T.PsString> | T.FullForm<T.PsString> | " " | "">): T.FullForm<T.PsString> {
|
export function concatPsString(...items: Array<T.PsString | T.LengthOptions<T.PsString> | T.FullForm<T.PsString> | string | undefined>): T.FullForm<T.PsString> {
|
||||||
const hasPersonInflections = items.some((x) => ((typeof x !== "string") && ("mascSing" in x)));
|
const hasPersonInflections = items.some((x) => (x && (typeof x !== "string") && ("mascSing" in x)));
|
||||||
if (hasPersonInflections) {
|
if (hasPersonInflections) {
|
||||||
const forceInflection = (
|
const forceInflection = (
|
||||||
arr: Array<T.FullForm<T.PsString> | " " | "">,
|
arr: Array<T.FullForm<T.PsString> | string | undefined>,
|
||||||
inflection: T.PersonInflectionsField,
|
inflection: T.PersonInflectionsField,
|
||||||
): Array<T.SingleOrLengthOpts<T.PsString> | " " | ""> => (
|
): Array<T.SingleOrLengthOpts<T.PsString> | string | undefined> => (
|
||||||
arr.map((element) => (typeof element !== "string" && "mascSing" in element)
|
arr.map((element) => (element && typeof element !== "string" && "mascSing" in element)
|
||||||
? element[inflection]
|
? element[inflection]
|
||||||
: element
|
: element
|
||||||
)
|
)
|
||||||
|
@ -53,14 +53,14 @@ export function concatPsString(...items: Array<T.PsString | T.LengthOptions<T.Ps
|
||||||
femPlur: concatPsString(...forceInflection(items, "femPlur")),
|
femPlur: concatPsString(...forceInflection(items, "femPlur")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const itemsWOutPersInfs = items as ("" | " " | T.SingleOrLengthOpts<T.PsString>)[];
|
const itemsWOutPersInfs = items as (string | T.SingleOrLengthOpts<T.PsString>)[];
|
||||||
const hasLengthOptions = itemsWOutPersInfs.some((x) => (typeof x !== "string") && ("long" in x));
|
const hasLengthOptions = itemsWOutPersInfs.some((x) => (typeof x !== "string") && ("long" in x));
|
||||||
if (hasLengthOptions) {
|
if (hasLengthOptions) {
|
||||||
const forceLength = (
|
const forceLength = (
|
||||||
arr: Array<T.SingleOrLengthOpts<T.PsString> | " ">,
|
arr: Array<T.SingleOrLengthOpts<T.PsString> | string | undefined>,
|
||||||
length: "long" | "short" | "mini",
|
length: "long" | "short" | "mini",
|
||||||
): Array<T.PsString | " "> => (
|
): Array<T.PsString | string | undefined> => (
|
||||||
arr.map((element) => (element !== " " && "long" in element)
|
arr.map((element) => (element && typeof element !== "string" && "long" in element)
|
||||||
? element[length] || element.short
|
? element[length] || element.short
|
||||||
: element
|
: element
|
||||||
)
|
)
|
||||||
|
@ -68,17 +68,17 @@ export function concatPsString(...items: Array<T.PsString | T.LengthOptions<T.Ps
|
||||||
const hasMini = itemsWOutPersInfs.some((x) => typeof x !== "string" && ("mini" in x));
|
const hasMini = itemsWOutPersInfs.some((x) => typeof x !== "string" && ("mini" in x));
|
||||||
return {
|
return {
|
||||||
...hasMini ? {
|
...hasMini ? {
|
||||||
mini: concatPsString(...forceLength(items as Array<T.SingleOrLengthOpts<T.PsString> | " ">, "mini")),
|
mini: concatPsString(...forceLength(items as Array<T.SingleOrLengthOpts<T.PsString> | string | undefined>, "mini")),
|
||||||
} : {},
|
} : {},
|
||||||
short: concatPsString(...forceLength(items as Array<T.SingleOrLengthOpts<T.PsString> | " ">, "short")),
|
short: concatPsString(...forceLength(items as Array<T.SingleOrLengthOpts<T.PsString> | string | undefined>, "short")),
|
||||||
long: concatPsString(...forceLength(items as Array<T.SingleOrLengthOpts<T.PsString> | " ">, "long")),
|
long: concatPsString(...forceLength(items as Array<T.SingleOrLengthOpts<T.PsString> | string | undefined>, "long")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const itemsWOutLengthOptions = itemsWOutPersInfs as ("" | " " | T.PsString)[];
|
const itemsWOutLengthOptions = itemsWOutPersInfs as (string | undefined | T.PsString)[];
|
||||||
const concatField = (k: T.PsStringField): string => (
|
const concatField = (k: T.PsStringField): string => (
|
||||||
itemsWOutLengthOptions.map((item): string => {
|
itemsWOutLengthOptions.map((item): string => {
|
||||||
if (item === " ") return " ";
|
if (item === undefined) return "";
|
||||||
if (item === "") return "";
|
if (typeof item === "string") return item;
|
||||||
return item[k];
|
return item[k];
|
||||||
}).join("")
|
}).join("")
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue