import { CamelToPascal } from './utility-types'; /** * Converts string to kebab case * * @param {string} string * @returns {string} A kebabized string */ export const toKebabCase = (string: string) => string.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase(); /** * Converts string to camel case * * @param {string} string * @returns {string} A camelized string */ export const toCamelCase = (string: T) => string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase(), ); /** * Converts string to pascal case * * @param {string} string * @returns {string} A pascalized string */ export const toPascalCase = (string: T): CamelToPascal => { const camelCase = toCamelCase(string); return (camelCase.charAt(0).toUpperCase() + camelCase.slice(1)) as CamelToPascal; }; /** * Merges classes into a single string * * @param {array} classes * @returns {string} A string of classes */ export const mergeClasses = (...classes: ClassType[]) => classes .filter((className, index, array) => { return ( Boolean(className) && (className as string).trim() !== '' && array.indexOf(className) === index ); }) .join(' ') .trim();