File tree 3 files changed +23
-25
lines changed
3 files changed +23
-25
lines changed Original file line number Diff line number Diff line change @@ -90,10 +90,10 @@ export type Preposition = Readonly<{
90
90
object : NounPhrase ;
91
91
emphasis : boolean ;
92
92
} > ;
93
- export type Sentence =
93
+ export type Sentence = Readonly < {
94
+ clauses : ReadonlyArray < Clause > ;
95
+ punctuation : string ;
96
+ } > ;
97
+ export type Sentences =
94
98
| Readonly < { type : "free form" ; text : string } >
95
- | Readonly < {
96
- type : "sentence" ;
97
- clauses : ReadonlyArray < Clause > ;
98
- punctuation : string ;
99
- } > ;
99
+ | Readonly < { type : "sentences" ; sentences : ReadonlyArray < Sentence > } > ;
Original file line number Diff line number Diff line change @@ -132,24 +132,22 @@ function clause(ast: English.Clause): string {
132
132
}
133
133
}
134
134
function sentence ( sentence : English . Sentence ) : string {
135
- let text : string ;
136
- switch ( sentence . type ) {
135
+ const capitalized = capitalize ( sentence . clauses . map ( clause ) . join ( ", " ) ) ;
136
+ return `${ capitalized } ${ sentence . punctuation } ` ;
137
+ }
138
+ export function multipleSentences (
139
+ sentences : English . Sentences ,
140
+ ) : string {
141
+ switch ( sentences . type ) {
137
142
case "free form" :
138
- text = sentence . text ;
139
- break ;
140
- case "sentence" :
141
- text = `${
142
- sentence . clauses . map ( clause ) . join ( ", " )
143
- } ${ sentence . punctuation } `;
144
- break ;
143
+ return capitalize ( sentences . text ) ;
144
+ case "sentences" :
145
+ return sentences . sentences . map ( sentence ) . join ( " " ) ;
145
146
}
147
+ }
148
+ function capitalize ( text : string ) : string {
146
149
return text . replace (
147
150
/ (?< ! [ < & \p{ Alpha} \p{ Nd} \p{ Nl} \p{ No} ] ) [ \p{ Alpha} \p{ Nd} \p{ Nl} \p{ No} ] / u,
148
151
( character ) => character . toLocaleUpperCase ( ) ,
149
152
) ;
150
153
}
151
- export function multipleSentences (
152
- sentences : ReadonlyArray < English . Sentence > ,
153
- ) : string {
154
- return sentences . map ( sentence ) . join ( " " ) ;
155
- }
Original file line number Diff line number Diff line change @@ -177,23 +177,23 @@ function sentence(
177
177
}
178
178
export function multipleSentences (
179
179
sentences : TokiPona . MultipleSentences ,
180
- ) : ArrayResult < ReadonlyArray < English . Sentence > > {
180
+ ) : ArrayResult < English . Sentences > {
181
181
switch ( sentences . type ) {
182
182
case "single word" : {
183
183
const { word } = sentences ;
184
184
return new ArrayResult ( dictionary . get ( word ) ! . definitions )
185
185
. flatMap ( definitionAsPlainString )
186
- . map < English . Sentence > ( ( definition ) => ( {
186
+ . map ( ( definition ) => ( {
187
187
type : "free form" ,
188
188
text : definition ,
189
- } ) )
190
- . map ( ( definition ) => [ definition ] ) ;
189
+ } ) ) ;
191
190
}
192
191
case "sentences" :
193
192
return ArrayResult . combine (
194
193
...sentences . sentences . map ( ( value , i ) =>
195
194
sentence ( value , i === sentences . sentences . length - 1 )
196
195
) ,
197
- ) ;
196
+ )
197
+ . map ( ( sentences ) => ( { type : "sentences" , sentences } ) ) ;
198
198
}
199
199
}
You can’t perform that action at this time.
0 commit comments