/** Converts the keys of an object to kebab case. */ export const objectKeysToKebabCase = (object: Record = {}) => Object.keys(object).reduce( (acc, key) => Object.assign(acc, { [toKebabCase(key)]: object[key] }), {} as Record ) export const objectKeysToCamelCase = (object: Record = {}) => Object.keys(object).reduce( (acc, key) => Object.assign(acc, { [toCamelCase(key)]: object[key] }), {} as Record ) export function toKebabCase(str: string) { const KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g return toCamelCase(str).replace(KEBAB_REGEX, function (match) { return '-' + match.toLowerCase() }) } export function toCamelCase(input: string): string { input = input.replace(/[-_ ]+/g, ' ') input = input.charAt(0).toLowerCase() + input.slice(1) return input .split(/\s+/) .map((word, index) => (index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))) .join('') }