Open xvno opened 3 years ago
// snake case => camel case
function s2c(str) {
if('string' === typeof str) {
return str.replace(/([-_]+(\w))/ig, (all, first, second) => {
return second.toUpperCase();
});
} else {
return str;
}
}
// camel case => snake case
function c2s(str) {
if('string' === typeof str) {
return str.replace(/([A-Z])/g, (all, first) => `_${first.toLowerCase()}`);
} else {
return str;
}
}
Refs