diff options
Diffstat (limited to 'src/language.ts')
-rw-r--r-- | src/language.ts | 99 |
1 files changed, 64 insertions, 35 deletions
diff --git a/src/language.ts b/src/language.ts index 0721e09..c0360b8 100644 --- a/src/language.ts +++ b/src/language.ts @@ -1,16 +1,16 @@ export enum VowelHeight { - Open, - NearOpen, - OpenMid, - Mid, - CloseMid, - NearClose, - Close, + Open = 'open', + NearOpen = 'nearOpen', + OpenMid = 'openMid', + Mid = 'mid', + CloseMid = 'closeMid', + NearClose = 'nearClose', + Close = 'close', } export enum VowelDepth { - Front, - Central, - Back, + Front = 'front', + Central = 'central', + Back = 'back', } export interface VowelFeatures { height: VowelHeight; @@ -106,33 +106,33 @@ export function vowelFeaturesToIpa(features: VowelFeatures): string { export enum ConsonantPlace { - Bilabial, - Labiodental, - Linguolabial, - Dental, - Alveolar, - Postalveolar, - Retroflex, - Palatal, - Velar, - Uvular, - Pharyngeal, - Glottal, + Bilabial = 'bilabial', + Labiodental = 'labiodental', + Linguolabial = 'labiolingual', + Dental = 'dental', + Alveolar = 'alveolar', + Postalveolar = 'postalveolar', + Retroflex = 'retroflex', + Palatal = 'palatal', + Velar = 'velar', + Uvular = 'uvular', + Pharyngeal = 'pharyngeal', + Glottal = 'glottal', } export enum ConsonantManner { - Nasal, - Plosive, - SibilantAffricate, - NonSibilantAffricate, - SibilantFricative, - NonSibilantFricative, - Approximant, - Tap, - Trill, - LateralAffricate, - LateralFricative, - LateralApproximant, - LateralTap, + Nasal = 'nasal', + Plosive = 'plosive', + SibilantAffricate = 'sibilantAffricate', + NonSibilantAffricate = 'nonSibilantAffricate', + SibilantFricative = 'sibilantFricative', + NonSibilantFricative = 'nonSibilantFricative', + Approximant = 'approximant', + Tap = 'tap', + Trill = 'trill', + LateralAffricate = 'lateralAffricate', + LateralFricative = 'lateralFricative', + LateralApproximant = 'lateralApproximant', + LateralTap = 'lateralTap', } export interface ConsonantFeatures { place: ConsonantPlace; @@ -480,3 +480,32 @@ export function consonantFeaturesToIpa(features: ConsonantFeatures): string { } } } + + +export function isConsonantPossible(features: ConsonantFeatures): boolean { + return consonantFeaturesToIpa(features) !== ''; +} + + +// get all of the consonants based on the features selected +export function pickConsonants( + places: ConsonantPlace[], + manners: ConsonantManner[], + voicing: [boolean, boolean], +): ConsonantFeatures[] { + return places.map<ConsonantFeatures[]>( + place => manners.map<ConsonantFeatures[]>( + manner => { + const [ unvoiced, voiced ] = voicing; + const result = []; + if (unvoiced) { + result.push({ place, manner, voice: false }); + } + if (voiced) { + result.push({ place, manner, voice: true }); + } + return result; + } + ).flat() + ).flat().filter(isConsonantPossible); +} |