UNPKG

@polgubau/utils

Version:

A collection of utility functions for TypeScript

98 lines (96 loc) 3.37 kB
/** * Converts a string to camel case. * @param {string} str - The string to convert. * @returns {string} The camel-cased string. * @example * ```javascript * toCamelCase('hello-world'); // 'helloWorld' * toCamelCase('hello_world'); // 'helloWorld' * ``` */ declare function toCamelCase(str: string): string; /** * Converts a string to title case. * @param {string} str - The string to convert. * @returns {string} The title-cased string. */ declare function toTitleCase(str: string): string; /** * Converts a string to kebab case. * @param {string} str - The string to convert. * @returns {string} The kebab-cased string. */ declare function toKebabCase(str: string): string; /** * Converts a string to upper case. * @param {string} str - The string to convert. * @returns {string} The uppercased string. */ declare function toUpperCase(str: string): string; /** * Converts a string to lower case. * @param {string} str - The string to convert. * @returns {string} The lowercased string. */ declare function toLowerCase(str: string): string; /** * Capitalizes the first letter of a string. * @param {string} str - The string to capitalize. * @returns {string} The capitalized string. */ declare function capitalize(str: string): string; /** * Removes all whitespace from a string. * @param {string} str - The string to remove whitespace from. * @returns {string} The whitespace-free string. */ declare function removeWhitespace(str: string): string; /** * Reverses a string. * @param {string} str - The string to reverse. * @returns {string} The reversed string. */ declare function reverseString(str: string): string; /** * Truncates a string to a specified length. * @param {string} str - The string to truncate. * @param {number} length - The maximum length of the truncated string. * @param {string} suffix - Optional suffix to append to truncated string. Defaults to '...'. * @returns {string} The truncated string. */ declare function truncateString(str: string, length?: number, suffix?: string): string; /** * Formats a string to be more human-readable. * @param {string} str - The string to format. * @returns {string} The formatted string. * @example * ```javascript * formatString('helloWorld'); // 'Hello World' * formatString('helloWorldAgain'); // 'Hello World Again' * ``` * */ declare function formatString(str: string): string; /** * @name randomString * @description Generates a random string of a specified length. * @param {number} length - The length of the random string to generate. * @returns {string} The random string. * @example ```javascript * randomString(10); // 'aBcDeFgHiJ' * randomString(5); // 'aBcDe' * ``` */ declare const randomString: (length?: number) => string; /** * @name lowerAndNoSpace * @description Converts a string to lowercase and removes all whitespace. * @param {string} str - The string to convert. * @returns {string} The converted string. * @example ```javascript * lowerAndNoSpace('Global Wizard Flow'); // 'globalwizardflow' * lowerAndNoSpace('Global Wizard Flow'); // 'globalwizardflow' * ``` * */ declare const lowerAndNoSpace: (str: string) => string; export { capitalize, formatString, lowerAndNoSpace, randomString, removeWhitespace, reverseString, toCamelCase, toKebabCase, toLowerCase, toTitleCase, toUpperCase, truncateString };