Skip to content

Commit

Permalink
Merge pull request #245 from act10ns/fix-pluralize-undefined-object
Browse files Browse the repository at this point in the history
Fix pluralize on undefined object
  • Loading branch information
satterly committed Jul 2, 2022
2 parents 481faab + c57e0e5 commit bf7d450
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/handlebars.ts
Expand Up @@ -8,6 +8,7 @@ Handlebars.registerHelper('truncate', (text, size) => text.substring(0, size))
Handlebars.registerHelper('default', (want, fallback) => (want || want === 0 || want === false ? want : fallback))

Handlebars.registerHelper('pluralize', (items, ...args) => {
items = items ?? []
const count = typeof items === 'number' ? items : items.length
const singular = args.length === 1 ? 'item' : args[0]
const plural = args.length === 3 ? args[1] : `${singular}s`
Expand Down

0 comments on commit bf7d450

Please sign in to comment.