VDL Plugin SDK

pluralize

Import from @varavel/vdl-plugin-sdk/utils/strings.

function pluralize(
   word, 
   count?, 
   inclusive?
): string;

Pluralize or singularize a word based on a count.

This function uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word.

Parameters

ParameterTypeDescription
wordstringThe word to pluralize or singularize.
count?numberOptional number indicating how many of the word exist. - If 1, returns the singular form. - If other than 1, returns the plural form.
inclusive?booleanWhether to prefix the result with the number (e.g., "3 ducks"). Defaults to false.

Returns

string

The pluralized or singularized word, optionally prefixed by the count.

Example

pluralize('test')
// "tests"

pluralize('test', 1)
// "test"

pluralize('test', 5, true)
// "5 tests"

pluralize('person', 2)
// "people"

See

Powered by pluralize (MIT License): https://github.com/plurals/pluralize