@@ -38,7 +38,7 @@ function shouldCapitalize(lastChar: string): boolean {
3838
3939let spanishSentenceTracker = "" ;
4040export async function punctuateWord (
41- previousWord : string ,
41+ previousWord : string | undefined ,
4242 currentWord : string ,
4343 index : number ,
4444 maxindex : number ,
@@ -47,7 +47,8 @@ export async function punctuateWord(
4747
4848 const currentLanguage = Config . language . split ( "_" ) [ 0 ] ;
4949
50- const lastChar = Strings . getLastChar ( previousWord ) ;
50+ const lastChar =
51+ previousWord !== undefined ? Strings . getLastChar ( previousWord ) : undefined ;
5152
5253 const funbox = findSingleActiveFunboxWithFunction ( "punctuateWord" ) ;
5354 if ( funbox ) {
@@ -56,7 +57,7 @@ export async function punctuateWord(
5657 if (
5758 currentLanguage !== "code" &&
5859 currentLanguage !== "georgian" &&
59- ( index === 0 || shouldCapitalize ( lastChar ) )
60+ ( index === 0 || ( lastChar !== undefined && shouldCapitalize ( lastChar ) ) )
6061 ) {
6162 //always capitalise the first word or if there was a dot unless using a code alphabet or the Georgian language
6263
@@ -371,7 +372,7 @@ function applyFunboxesToWord(
371372
372373async function applyBritishEnglishToWord (
373374 word : string ,
374- previousWord : string ,
375+ previousWord : string | undefined ,
375376) : Promise < string > {
376377 if ( ! Config . britishEnglish ) return word ;
377378 if ( ! Config . language . includes ( "english" ) ) return word ;
@@ -743,7 +744,7 @@ type GetNextWordReturn = {
743744export async function getNextWord (
744745 wordIndex : number ,
745746 wordsBound : number ,
746- previousWord : string ,
747+ previousWord : string | undefined ,
747748 previousWord2 : string | undefined ,
748749) : Promise < GetNextWordReturn > {
749750 console . debug ( "Getting next word" , {
@@ -807,7 +808,9 @@ export async function getNextWord(
807808
808809 const funboxFrequency = getFunboxWordsFrequency ( ) ?? "normal" ;
809810 let randomWord = currentWordset . randomWord ( funboxFrequency ) ;
810- const previousWordRaw = previousWord . replace ( / [ . ? ! " : \- , ] / g, "" ) . toLowerCase ( ) ;
811+ const previousWordRaw = previousWord
812+ ?. replace ( / [ . ? ! " : \- , ] / g, "" )
813+ . toLowerCase ( ) ;
811814 const previousWord2Raw = previousWord2
812815 ?. replace ( / [ . ? ! " : \- , ' ] / g, "" )
813816 . toLowerCase ( ) ;
0 commit comments