Skip to content

Commit

Permalink
fix: Check for null on makeReplacements (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiCO2k committed Jan 8, 2024
1 parent d31af79 commit 81454a6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,15 @@ export class I18n {
/**
* Make the place-holder replacements on a line.
*/
makeReplacements(message: string, replacements?: ReplacementsInterface): string {
makeReplacements(message?: string, replacements?: ReplacementsInterface): string {
const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1)

Object.entries(replacements || [])
.sort((a, b) => (a[0].length >= b[0].length ? -1 : 1))
.forEach(([key, value]) => {
value = value.toString()

message = message
message = (message || '')
.replace(new RegExp(`:${key}`, 'g'), value)
.replace(new RegExp(`:${key.toUpperCase()}`, 'g'), value.toUpperCase())
.replace(new RegExp(`:${capitalize(key)}`, 'g'), capitalize(value))
Expand Down

0 comments on commit 81454a6

Please sign in to comment.