UNPKG

@nish1896/rhf-mui-components

Version:

A suite of 20+ production-ready react-hook-form components built with material-ui. Fully typed, tree-shakable, and optimized for enterprise-grade forms.

20 lines (19 loc) 763 B
//#region src/utils/text-transform.ts /** * Function to generate easy-to-read form labels from a given string. * * Examples - * "fullName" to "Full Name" * "last_name" to "Last Name" * "parseJSONData" to "Parse JSON Data" * "enable_HTTP_Config" to "Enable HTTP Config" * users.0.email -> Users Email */ function fieldNameToLabel(str) { return str.replace(/\.\d+/g, "").replace(/[._]/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase()).trim(); } function fieldNameToId(fieldName) { return fieldName.replace(/\[(\d+)\]/g, "-$1").replace(/\./g, "-").replace(/[^a-zA-Z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, ""); } //#endregion export { fieldNameToId, fieldNameToLabel };