UNPKG

@junaidatari/json2ts

Version:

Convert JSON objects to TypeScript interfaces automatically.

29 lines (28 loc) 1.34 kB
import type { CaseType } from '../typings/global'; export default abstract class StringUtils { /** * Capitalizes the first letter of a string. * If the input is null, undefined, or empty, returns an empty string. * @param str - The string to capitalize * @returns The capitalized string, or empty string if input is falsy */ static capitalize(str: string): string; /** * Formats a string according to the specified case type. * * @param name - The string to format * @param [caseType] - The case type to apply ('camel', 'lower_snake', 'pascal', 'upper_snake', 'kebab', or undefined) * @returns The formatted string in the specified case, or the original name if caseType is undefined * * @example * ```typescript * StringUtils.formatName('userName', 'camel') // returns 'userName' * StringUtils.formatName('userName', 'lower_snake') // returns 'user_name' * StringUtils.formatName('userName', 'pascal') // returns 'UserName' * StringUtils.formatName('userName', 'upper_snake') // returns 'USER_NAME' * StringUtils.formatName('userName', 'kebab') // returns 'user-name' * StringUtils.formatName('userName', undefined) // returns 'userName' * ``` */ static formatName(name: string, caseType?: CaseType | undefined): string; }