@bearz/strings
Version:
A collection of string utilities to avoid extra allocations and enable case insensitivity comparisons.
58 lines (57 loc) • 2.44 kB
TypeScript
/**
* This function adds pluralization support to every String object.
* @param str The subject string.
* @param plural Overrides normal output with said String.(optional)
* @returns Singular English language nouns are returned in plural form.
* @example
*
* const inflection = require( 'inflection' );
*
* inflection.pluralize( 'person' ); // === 'people'
* inflection.pluralize( 'octopus' ); // === 'octopuses'
* inflection.pluralize( 'Hat' ); // === 'Hats'
* inflection.pluralize( 'person', 'guys' ); // === 'guys'
*/
export declare function pluralize(str: string, plural?: string): string;
/**
* This function adds singularization support to every String object.
* @param str The subject string.
* @param singular Overrides normal output with said String.(optional)
* @returns Plural English language nouns are returned in singular form.
* @example
*
* const inflection = require( 'inflection' );
*
* inflection.singularize( 'people' ); // === 'person'
* inflection.singularize( 'octopuses' ); // === 'octopus'
* inflection.singularize( 'Hats' ); // === 'Hat'
* inflection.singularize( 'guys', 'person' ); // === 'person'
*/
export declare function singularize(str: string, singular?: string): string;
/**
* This function will pluralize or singularlize a String appropriately based on a number value
* @param str The subject string.
* @param count The number to base pluralization off of.
* @param singular Overrides normal output with said String.(optional)
* @param plural Overrides normal output with said String.(optional)
* @returns English language nouns are returned in the plural or singular form based on the count.
* @example
*
* const inflection = require( 'inflection' );
*
* inflection.inflect( 'people' 1 ); // === 'person'
* inflection.inflect( 'octopuses' 1 ); // === 'octopus'
* inflection.inflect( 'Hats' 1 ); // === 'Hat'
* inflection.inflect( 'guys', 1 , 'person' ); // === 'person'
* inflection.inflect( 'inches', 1.5 ); // === 'inches'
* inflection.inflect( 'person', 2 ); // === 'people'
* inflection.inflect( 'octopus', 2 ); // === 'octopuses'
* inflection.inflect( 'Hat', 2 ); // === 'Hats'
* inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys'
*/
export declare function inflect(
str: string,
count: number,
singular?: string,
plural?: string,
): string;