Files
twenty/packages/twenty-front/src/pages/settings/data-model/utils/compute-metadata-name-from-label.utils.ts
Ketan Mehta 51c54d4c5b validation on Select field (#8316)
fix #8204
I changed "API keys" to "API values".
Stopped inputting special characters in Select field option keys.

@lucasbordeau please check the changes and tell me if I need to do any
other changes. :)

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
2024-11-14 17:46:18 +01:00

23 lines
515 B
TypeScript

import camelCase from 'lodash.camelcase';
import { slugify } from 'transliteration';
export const computeMetadataNameFromLabel = (label: string): string => {
const prefixedLabel = /^\d/.test(label) ? `n${label}` : label;
if (prefixedLabel === '') {
return '';
}
const formattedString = slugify(prefixedLabel, {
trim: true,
separator: '_',
allowedChars: 'a-zA-Z0-9',
});
if (formattedString === '') {
throw new Error('Invalid label');
}
return camelCase(formattedString);
};