@plurid/plurid-functions
Version:
General Utility Functions for Plurid Applications
140 lines (139 loc) • 3.65 kB
TypeScript
export declare const removeWhitespace: (value: string | undefined) => string;
/**
* Capitalizes the first letter of the word.
*
* ``` text
* e.g. foo -> Foo
* ```
*
* @param value
*/
export declare const capitalize: (value: string) => string;
/**
* Capitalizes the first letter of every word.
*
* ``` text
* e.g. foo boo -> Foo Boo
* ```
*
* @param value
*/
export declare const capitalizeAll: (value: string) => string;
/**
* Truncates the `value` to a given `length` adding the `ending`.
*
* ``` text
* e.g. 1234567890 -> 1234…
* ```
*
* ``` typescript
* truncate('1234567890', 4)
* ```
*
* @param value
* @param length default `100`
* @param ending default `'…'`
* @returns
*/
export declare const truncate: (value: string | undefined, length?: number, ending?: string) => string;
/**
* Trims the middle of the `value` keeping the lateral `length`
* and replacing with the `middle`.
*
* ``` text
* e.g. 12345678901234567890 -> 123456…567890
* ```
*
* @param value
* @param length default `6`
* @param middle default `'…'`
* @param startLength
* @param endLength
* @returns
*/
export declare const trimMiddle: (value: string | undefined, length?: number, middle?: string, startLength?: number, endLength?: number) => string;
/**
* Given a text string, e.g. 'one two three',
* it removes the last word, 'three', returning 'one two'.
*
* If the text string is one word, 'one', it returns ''.
*
* @param text Text string.
*/
export declare const removeLastWord: (text: string) => string;
/**
* Given `PascalCaseValue` it returns `pascal.case.value`.
*
* @param value
* @param lowercase default `true`
* @returns
*/
export declare const pascalCaseToDotNotation: (value: string, lowercase?: boolean) => string;
/**
* Given `PascalCaseValue` it returns `Pascal_Case_Value`.
*
* @param value
* @returns
*/
export declare const pascalCaseToSnakeCase: (value: string) => string;
/**
* Given `Pascal_Case_Value` it returns `PascalCaseValue`.
*
* @param value
* @returns
*/
export declare const snakeCaseToPascalCase: (value: string) => string;
/**
* Converts `Camel Case Value` to `camelCaseValue`.
*
* @param text
*/
export declare const toCamelCase: (value: string) => string;
/**
* Shuffles the characters of the `text`.
*
* @param text
* @returns
*/
export declare const shuffle: (text: string) => string;
/**
* Removes the `character` at the start of the `value`.
*
* @param value
* @param character
* @param count default `1`
* @returns
*/
export declare const trimStart: (value: string, character: string, count?: number) => string;
/**
* Removes the `character` at the end of the `value`.
*
* @param value
* @param character
* @param count default `1`
* @returns
*/
export declare const trimEnd: (value: string, character: string, count?: number) => string;
/**
* Pluralizes a `text` based on a `value`.
*
* ``` typescript
* pluralize(1, 'day'); // '1 day'
* pluralize(2, 'day'); // '2 days'
*
* pluralize(1, 'bus', 'es'); // '1 bus'
* pluralize(2, 'bus', 'es'); // '1 buses'
*
* pluralize(1, 'wolf', { replace: 'wolves' }); // '1 wolf'
* pluralize(2, 'wolf', { replace: 'wolves' }); // '2 wolves'
* ```
*
* @param value
* @param text
* @param overload `string | { replace: string }`
* @returns
*/
export declare function pluralize(value: number, text: string, end: string): string;
export declare function pluralize(value: number, text: string, options: {
replace: string;
}): string;