nestjs-ddd-cli
Version:
CLI for generating NestJS DDD boilerplate code
47 lines • 1.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toPascalCase = toPascalCase;
exports.toCamelCase = toCamelCase;
exports.toKebabCase = toKebabCase;
exports.toSnakeCase = toSnakeCase;
exports.toPlural = toPlural;
exports.toSingular = toSingular;
exports.toTableName = toTableName;
const pluralize_1 = __importDefault(require("pluralize"));
function toPascalCase(str) {
return str
.split(/[-_ ]/)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join('');
}
function toCamelCase(str) {
const pascal = toPascalCase(str);
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
}
function toKebabCase(str) {
return str
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/[\s_]+/g, '-')
.toLowerCase();
}
function toSnakeCase(str) {
return str
.replace(/([a-z])([A-Z])/g, '$1_$2')
.replace(/[\s-]+/g, '_')
.toLowerCase();
}
function toPlural(str) {
return (0, pluralize_1.default)(str);
}
function toSingular(str) {
return pluralize_1.default.singular(str);
}
function toTableName(entityName) {
const singular = toSingular(entityName);
const snakeCase = toSnakeCase(singular);
return toPlural(snakeCase);
}
//# sourceMappingURL=naming.utils.js.map