UNPKG

@cowwoc/requirements

Version:

A fluent API for enforcing design contracts with automatic message generation.

32 lines 1.07 kB
/** * Generates the singular or plural form of an element type. */ class Pluralizer { singular; plural; static CHARACTER = new Pluralizer("character", "characters"); static KEY = new Pluralizer("key", "keys"); static VALUE = new Pluralizer("value", "values"); static ELEMENT = new Pluralizer("element", "elements"); static ENTRY = new Pluralizer("entry", "entries"); /** * @param singular - the singular form of the element * @param plural - the plural form of the element */ constructor(singular, plural) { this.singular = singular; this.plural = plural; } /** * @param count - a number of elements * @param name - the name of the parameter containing the number of elements (`null` if absent) * @returns the singular or plural form of the element type (in lowercase) */ nameOf(count, name) { if (count === 1 && name === null) return this.singular; return this.plural; } } export { Pluralizer }; //# sourceMappingURL=Pluralizer.mjs.map