From 09d9ea5737db16198fb4644813f131656c39bd15 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sun, 17 Oct 2021 21:26:49 -0400 Subject: [PATCH] countsylabbles --- package.json | 2 +- src/lib/accent-helpers.test.ts | 11 +++++++++++ src/lib/accent-helpers.ts | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 25eafa3..1c11ac6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.2.7", + "version": "1.2.8", "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/accent-helpers.test.ts b/src/lib/accent-helpers.test.ts index 30b36a4..2f3eebe 100644 --- a/src/lib/accent-helpers.test.ts +++ b/src/lib/accent-helpers.test.ts @@ -14,6 +14,7 @@ import { accentOnNFromEnd, splitUpSyllables, hasAccents, + countSyllables, } from "./accent-helpers"; const toAccentFront = [ @@ -60,6 +61,16 @@ test(`splitUpSyllables should work`, () => { expect(splitUpSyllables("akheestul")).toEqual(["akh", "eest", "ul"]); }); +test("countSyllables", () => { + expect(countSyllables("saRéy")).toEqual(2); + expect(countSyllables("saRey")).toEqual(2); + expect(countSyllables("zRú")).toEqual(1); + expect(countSyllables("zRu")).toEqual(1); + expect(countSyllables("zRU")).toEqual(1); + expect(countSyllables("tbtkz")).toEqual(0); + expect(countSyllables({ p: "اونۍ", f: "onúy, ownúy" })).toEqual(2); +}); + test(`accentOnFSylsOnNFromEnd should work`, () => { expect(accentFSylsOnNFromEnd(["pu", "xtaa", "nu"], 0)).toBe("puxtaanú"); expect(accentFSylsOnNFromEnd(["leed", "ul", "ey"], 1)).toBe("leedúley"); diff --git a/src/lib/accent-helpers.ts b/src/lib/accent-helpers.ts index 9d21cdb..3ac16bd 100644 --- a/src/lib/accent-helpers.ts +++ b/src/lib/accent-helpers.ts @@ -55,7 +55,7 @@ export function accentPastParticiple(s: T.PsString): T.PsString { } export function splitUpSyllables(f: string): string[] { - return f.match(/ |([^a|e|i|o|u| ]*(aa|a|ey|ee|e|oo|o|i|u)[^a|e|i|o|u| ]*)/g) || [] as string[]; + return f.match(/ |([^a|e|i|o|u| ]*(aa|a|ey|ee|e|oo|o|i|u)[^a|e|i|o|u| ]*)/ig) || [] as string[]; } export function countSyllables(f: T.PsString | string): number {