camelToSnakeCase & snakeToCamelCase

2023. 4. 17. 17:44개발/토막난 상식

반응형
function camelToSnakeCase(str) {
  return str.replace(/([a-z])([A-Z0-9])/g, '$1_$2')
            .replace(/([0-9])([a-zA-Z])/g, '$1_$2')
            .toLowerCase();
}
function camelToSnakeCase(str) {
  return str.replace(/([a-z\d])([A-Z])/g, '$1_$2')
            .toLowerCase();
}
function snakeToCamelCase(str) {
  return str.replace(/([-_][a-z])/g, (match) => match.toUpperCase().replace(/[-_]/g, ''));
}
function snakeToCamelCase(str) {
  return str.replace(/([-_][a-z\d])/g, (match) => match.toUpperCase().replace(/[-_]/g, ''));
}

통일해서 씁시다

반응형