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>
23 lines
515 B
TypeScript
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);
|
|
};
|