@@ -20,7 +20,6 @@ import {
20
20
numberToSpokenForm ,
21
21
ordinalToSpokenForm ,
22
22
} from "./defaultSpokenForms/numbers" ;
23
- import { surroundingPairNameToSpokenForm } from "./defaultSpokenForms/modifiers" ;
24
23
import { characterToSpokenForm } from "./defaultSpokenForms/characters" ;
25
24
import {
26
25
GeneratorSpokenFormMap ,
@@ -35,7 +34,7 @@ export class PrimitiveTargetSpokenFormGenerator {
35
34
handlePrimitiveTarget (
36
35
target : PartialPrimitiveTargetDescriptor ,
37
36
) : SpokenFormComponent {
38
- const components : SpokenFormComponents = [ ] ;
37
+ const components : SpokenFormComponent [ ] = [ ] ;
39
38
if ( target . modifiers != null ) {
40
39
components . push ( target . modifiers . map ( this . handleModifier ) ) ;
41
40
}
@@ -147,7 +146,7 @@ export class PrimitiveTargetSpokenFormGenerator {
147
146
148
147
private handleRelativeScopeInclusive (
149
148
modifier : RelativeScopeModifier ,
150
- ) : SpokenFormComponents {
149
+ ) : SpokenFormComponent {
151
150
const scope = this . handleScopeType ( modifier . scopeType ) ;
152
151
153
152
if ( modifier . length === 1 ) {
@@ -175,7 +174,7 @@ export class PrimitiveTargetSpokenFormGenerator {
175
174
176
175
private handleRelativeScopeExclusive (
177
176
modifier : RelativeScopeModifier ,
178
- ) : SpokenFormComponents {
177
+ ) : SpokenFormComponent {
179
178
const scope = this . handleScopeType ( modifier . scopeType ) ;
180
179
const direction =
181
180
modifier . direction === "forward"
@@ -207,7 +206,7 @@ export class PrimitiveTargetSpokenFormGenerator {
207
206
) ;
208
207
}
209
208
210
- handleScopeType ( scopeType : ScopeType ) : SpokenForms {
209
+ handleScopeType ( scopeType : ScopeType ) : SpokenFormComponent {
211
210
switch ( scopeType . type ) {
212
211
case "oneOf" :
213
212
case "customRegex" :
@@ -220,10 +219,7 @@ export class PrimitiveTargetSpokenFormGenerator {
220
219
`Scope type '${ scopeType . type } ' with delimiter 'collectionBoundary'` ,
221
220
) ;
222
221
}
223
- const pair = surroundingPairNameToSpokenForm (
224
- this . spokenFormMap ,
225
- scopeType . delimiter ,
226
- ) ;
222
+ const pair = this . spokenFormMap . pairedDelimiter [ scopeType . delimiter ] ;
227
223
if ( scopeType . forceDirection != null ) {
228
224
const direction =
229
225
scopeType . forceDirection === "left"
@@ -239,7 +235,7 @@ export class PrimitiveTargetSpokenFormGenerator {
239
235
}
240
236
}
241
237
242
- private handleMark ( mark : PartialMark ) : SpokenFormComponents {
238
+ private handleMark ( mark : PartialMark ) : SpokenFormComponent {
243
239
switch ( mark . type ) {
244
240
case "decoratedSymbol" : {
245
241
const [ color , shape ] = mark . symbolColor . split ( "-" ) ;
@@ -314,7 +310,28 @@ export class PrimitiveTargetSpokenFormGenerator {
314
310
}
315
311
}
316
312
313
+ function pluralize ( name : SpokenFormComponent ) : SpokenFormComponent {
314
+ if ( typeof name === "string" ) {
315
+ return pluralizeString ( name ) ;
316
+ }
317
+
318
+ if ( Array . isArray ( name ) ) {
319
+ if ( name . length === 0 ) {
320
+ return name ;
321
+ }
322
+
323
+ const last = name [ name . length - 1 ] ;
324
+
325
+ return [ ...name . slice ( 0 , - 1 ) , pluralize ( last ) ] ;
326
+ }
327
+
328
+ return {
329
+ ...name ,
330
+ spokenForms : name . spokenForms . map ( pluralizeString ) ,
331
+ } ;
332
+ }
333
+
317
334
// FIXME: Properly pluralize
318
- function pluralize ( name : string ) : string {
335
+ function pluralizeString ( name : string ) : string {
319
336
return `${ name } s` ;
320
337
}
0 commit comments