@toolpad/utils
Version:
Shared utilities used by Toolpad packages.
81 lines • 2.77 kB
TypeScript
/**
* Makes the first letter of [str] uppercase.
* Not locale aware.
*/
export declare function uncapitalize(str: string): string;
/**
* Makes the first letter of [str] lowercase.
* Not locale aware.
*/
export declare function capitalize(str: string): string;
/**
* Capitalizes and joins all [parts].
*/
export declare function pascalCase(...parts: string[]): string;
/**
* Joins all [parts] and camelcases the result
*/
export declare function camelCase(...parts: string[]): string;
/**
* Turns a kebab-case string into a constant case string.
*/
export declare function kebabToConstant(input: string): string;
/**
* Turns a kebab-case string into a PascalCase string.
*/
export declare function kebabToPascal(input: string): string;
/**
* Generates a string for `base` by add a number until it's unique amongst a set of predefined names.
*/
export declare function generateUniqueString(base: string, existingNames: Set<string>): string;
/**
* Escape string for use in HTML.
*/
export declare function escapeHtml(unsafe: string): string;
/**
* Normalizes and removes all diacritics from a javascript string.
*
* See https://stackoverflow.com/a/37511463
*/
export declare function removeDiacritics(input: string): string;
export declare function isAbsoluteUrl(maybeUrl: string): boolean;
/**
* Removes a prefix from a string if it starts with it.
*/
export declare function removePrefix(input: string, prefix: string): string;
/**
* Removes a suffix from a string if it ends with it.
*/
export declare function removeSuffix(input: string, suffix: string): string;
/**
* Adds a prefix to a string if it doesn't start with it.
*/
export declare function ensurePrefix(input: string, prefix: string): string;
/**
* Adds a suffix to a string if it doesn't end with it.
*/
export declare function ensureSuffix(input: string, suffix: string): string;
/**
* Statically analyses a javascript source code for import statements and return the specifiers.
*
* NOTE: This function does a best effort without parsing the code. The result may contain false
* positives
*/
export declare function findImports(src: string): string[];
/**
* Limits the length of a string and adds ellipsis if necessary.
*/
export declare function truncate(str: string, maxLength: number, dots?: string): string;
/**
* Prepend a prefix to each line in the text
*/
export declare function prependLines(text: string, prefix: string): string;
/**
* Indent the text with [length] number of spaces
*/
export declare function indent(text: string, length?: number): string;
/**
* Returns true if the string is a valid javascript identifier
*/
export declare function isValidJsIdentifier(base: string): boolean;
export declare function guessTitle(str: string): string;