Skip to content

Conversation

@codeandcats
Copy link

@codeandcats codeandcats commented Mar 20, 2025

Thank you for this great little library, I use it often.

Problem

The option to include the number in the output is very convenient.

pluralize('record', recordCount, true) // '1000000 records'

versus

`${recordCount} ${pluralize('record', recordCount)}` // '1000000 records'

However most of the time I cannot use this option because I wish to format the number so that it includes grouping separators, to make large numbers much more readable for users.

`${formatInteger(recordCount)} ${pluralize('record', recordCount)}` // '1,000,000 records'

Proposed Solution

This PR adds support for passing a format function as the inclusive parameter

pluralize('record', recordCount, formatInteger) // '1,000,000 records'

Or alternatively, passing an Intl.NumberFormat instance

const integerFormatter = new Intl.NumberFormat(undefined, { useGrouping: true }) pluralize('record', recordCount, integerFormatter) // '1,000,000 records'

I have:
✅ Updated the JSDoc comments appropriately
✅ Updated Readme with formatting number examples
✅ Added tests which include full coverage for the added lines

Additionally

Despite using this wonderful library for years, I was unaware until now that you could pluralize pronouns. 😮 I don't believe the readme makes this especially obvious, so I added an example to hopefully better highlight this awesome capability.

Thank you for your consideration of this PR. If you agree with these changes I would love to see them published at your earliest convenience. Please let me know if you would like any changes.

@codeandcats codeandcats force-pushed the feat/number-formatting branch from 1349056 to be2ba2d Compare March 22, 2025 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant