UNPKG

dev-utils-plus

Version:

Type-safe utility functions for JavaScript/TypeScript: string, array, object, date, validation, crypto, format, math

170 lines 5.88 kB
/** * String utility functions for common web development tasks */ /** * Capitalizes the first letter of a string * @param str - The string to capitalize * @returns String with first letter capitalized * @example * capitalize('hello world') // 'Hello world' * capitalize('HELLO') // 'Hello' */ export declare function capitalize(str: string): string; /** * Converts a string to camelCase * @param str - The string to convert * @returns String in camelCase format * @example * toCamelCase('hello-world') // 'helloWorld' * toCamelCase('hello_world') // 'helloWorld' * toCamelCase('hello world') // 'helloWorld' */ export declare function toCamelCase(str: string): string; /** * Converts a string to kebab-case * @param str - The string to convert * @returns String in kebab-case format * @example * toKebabCase('HelloWorld') // 'hello-world' * toKebabCase('hello_world') // 'hello-world' * toKebabCase('hello world') // 'hello-world' */ export declare function toKebabCase(str: string): string; /** * Converts a string to snake_case * @param str - The string to convert * @returns String in snake_case format * @example * toSnakeCase('HelloWorld') // 'hello_world' * toSnakeCase('hello-world') // 'hello_world' * toSnakeCase('hello world') // 'hello_world' */ export declare function toSnakeCase(str: string): string; /** * Truncates a string to a specified length and adds ellipsis * @param str - The string to truncate * @param length - Maximum length of the result string * @param suffix - String to append when truncated (default: '...') * @returns Truncated string with suffix if needed * @example * truncate('Hello World', 8) // 'Hello...' * truncate('Hello World', 8, '~') // 'Hello W~' */ export declare function truncate(str: string, length: number, suffix?: string): string; /** * Removes HTML tags from a string * @param html - The HTML string to strip tags from * @returns String with HTML tags removed * @example * stripHtml('<p>Hello <strong>world</strong></p>') // 'Hello world' */ export declare function stripHtml(html: string): string; /** * Generates a random string of specified length * @param length - Length of the random string to generate * @param charset - Characters to use for generation (default: alphanumeric) * @returns Random string of specified length * @example * generateRandomString(8) // 'Kj3mN9qP' * generateRandomString(4, '0123456789') // '7294' */ export declare function generateRandomString(length: number, charset?: string): string; /** * Counts the number of words in a string * @param str - The string to count words in * @returns Number of words in the string * @example * wordCount('Hello world from JavaScript') // 4 * wordCount(' hello world ') // 2 */ export declare function wordCount(str: string): number; /** * Reverses a string * @param str - The string to reverse * @returns Reversed string * @example * reverse('hello') // 'olleh' * reverse('12345') // '54321' */ export declare function reverse(str: string): string; /** * Checks if a string is a palindrome * @param str - The string to check * @returns True if the string is a palindrome * @example * isPalindrome('A man a plan a canal Panama') // true * isPalindrome('race a car') // false */ export declare function isPalindrome(str: string): boolean; /** * Converts string to PascalCase * @param str - The string to convert * @returns String in PascalCase format * @example * toPascalCase('hello-world') // 'HelloWorld' * toPascalCase('hello_world') // 'HelloWorld' */ export declare function toPascalCase(str: string): string; /** * Removes extra whitespace and trims the string * @param str - The string to clean * @returns Cleaned string with normalized whitespace * @example * cleanWhitespace(' hello world ') // 'hello world' */ export declare function cleanWhitespace(str: string): string; /** * Escapes HTML characters in a string * @param str - The string to escape * @returns HTML-escaped string * @example * escapeHtml('<div>Hello & goodbye</div>') // '&lt;div&gt;Hello &amp; goodbye&lt;/div&gt;' */ export declare function escapeHtml(str: string): string; /** * Unescapes HTML entities in a string * @param str - The string to unescape * @returns HTML-unescaped string * @example * unescapeHtml('&lt;div&gt;Hello &amp; goodbye&lt;/div&gt;') // '<div>Hello & goodbye</div>' */ export declare function unescapeHtml(str: string): string; /** * Converts a string to title case * @param str - The string to convert * @returns String in title case * @example * toTitleCase('hello world from javascript') // 'Hello World From Javascript' */ export declare function toTitleCase(str: string): string; /** * Checks if string contains only letters * @param str - The string to check * @returns True if string contains only letters * @example * isAlpha('hello') // true * isAlpha('hello123') // false */ export declare function isAlpha(str: string): boolean; /** * Checks if string contains only alphanumeric characters * @param str - The string to check * @returns True if string contains only alphanumeric characters * @example * isAlphanumeric('hello123') // true * isAlphanumeric('hello-123') // false */ export declare function isAlphanumeric(str: string): boolean; /** * Pads a string to a certain length with characters * @param str - The string to pad * @param targetLength - The length of the resulting string * @param padString - The string to pad with (default: ' ') * @param padStart - Whether to pad at start (true) or end (false) * @returns Padded string * @example * padString('5', 3, '0', true) // '005' * padString('hello', 8, '!', false) // 'hello!!!' */ export declare function padString(str: string, targetLength: number, padString?: string, padStart?: boolean): string; //# sourceMappingURL=index.d.ts.map