@itrocks/rename
Version:
Switch the formatting of names stored in strings between different naming conventions
72 lines • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Str = exports.toVariable = exports.toUrl = exports.toRoute = exports.toProperty = exports.toMethod = exports.toFunction = exports.toField = exports.toCssId = exports.toCssClass = exports.toColumn = exports.toClass = void 0;
exports.lcFirst = lcFirst;
exports.toCamelCase = toCamelCase;
exports.toDisplay = toDisplay;
exports.toKebabCase = toKebabCase;
exports.toPascalCase = toPascalCase;
exports.toSnakeCase = toSnakeCase;
exports.ucFirst = ucFirst;
exports.toClass = toPascalCase;
exports.toColumn = toSnakeCase;
exports.toCssClass = toKebabCase;
exports.toCssId = toKebabCase;
exports.toField = toSnakeCase;
exports.toFunction = toCamelCase;
exports.toMethod = toCamelCase;
exports.toProperty = toCamelCase;
exports.toRoute = toKebabCase;
exports.toUrl = toKebabCase;
exports.toVariable = toCamelCase;
function lcFirst(string) {
return string[0].toLowerCase() + string.slice(1);
}
function toCamelCase(string) {
return string[0].toLowerCase() + string.slice(1)
.replace(/[ _-]([a-zA-Z0-9])/g, (_, high) => high.toUpperCase());
}
function toDisplay(string) {
return string[0].toLowerCase() + string.slice(1)
.replace(/[_-]/g, ' ')
.replace(/([a-z0-9])([A-Z])/g, (_, low, high) => low + ' ' + high.toLowerCase());
}
function toKebabCase(string) {
return string[0].toLowerCase() + string.slice(1)
.replace(/[ _]/g, '-')
.replace(/([a-z0-9])([A-Z])/g, (_, low, high) => low + '-' + high.toLowerCase());
}
function toPascalCase(string) {
return string[0].toUpperCase() + string.slice(1)
.replace(/[ _-]([a-zA-Z0-9])/g, (_, high) => high.toUpperCase());
}
function toSnakeCase(string) {
return string[0].toLowerCase() + string.slice(1)
.replace(/[ -]/g, '_')
.replace(/([a-z0-9])([A-Z])/g, (_, low, high) => low + '_' + high.toLowerCase());
}
function ucFirst(string) {
return string[0].toUpperCase() + string.slice(1);
}
class Str extends String {
camelCase() { return toCamelCase(this + ''); }
kebabCase() { return toKebabCase(this + ''); }
lcFirst() { return lcFirst(this + ''); }
pascalCase() { return toPascalCase(this + ''); }
snakeCase() { return toSnakeCase(this + ''); }
toClass() { return (0, exports.toClass)(this + ''); }
toColumn() { return (0, exports.toColumn)(this + ''); }
toCssClass() { return (0, exports.toCssClass)(this + ''); }
toCssId() { return (0, exports.toCssId)(this + ''); }
toDisplay() { return toDisplay(this + ''); }
toField() { return (0, exports.toField)(this + ''); }
toFunction() { return (0, exports.toFunction)(this + ''); }
toMethod() { return (0, exports.toMethod)(this + ''); }
toProperty() { return (0, exports.toProperty)(this + ''); }
toRoute() { return (0, exports.toRoute)(this + ''); }
toUrl() { return (0, exports.toUrl)(this + ''); }
toVariable() { return (0, exports.toVariable)(this + ''); }
ucFirst() { return ucFirst(this + ''); }
}
exports.Str = Str;
//# sourceMappingURL=rename.js.map