UNPKG

@nestjs-mod/common

Version:

A collection of utilities for unifying NestJS applications and modules

43 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DotEnvPropertyNameFormatter = exports.CLEAR_WORDS = void 0; const case_anything_1 = require("case-anything"); const default_context_name_1 = require("../../utils/default-context-name"); exports.CLEAR_WORDS = ['NESTJS', 'NEST', 'ENVIRONMENTS', 'ENVIRONMENT']; class DotEnvPropertyNameFormatter { constructor() { this.name = 'dotenv'; } example({ modelOptions, propertyOptions, modelRootOptions, }) { return { options: { 'modelRootOptions?.name': modelRootOptions?.name, 'modelOptions?.name': modelOptions?.name, 'propertyOptions.name': propertyOptions.name, 'propertyOptions.originalName': propertyOptions.originalName, }, logic: `concat all names and convert this to CONSTANT_CASE`, }; } format({ modelOptions, propertyOptions, modelRootOptions, }) { const modelRootOptionsName = modelRootOptions?.name?.trim().split(' ').join('_'); const modelOptionsName = modelOptions?.name?.trim().split(' ').join('_'); const prepareFullname = [ (0, default_context_name_1.defaultContextName)() !== modelRootOptionsName && modelRootOptionsName ? modelRootOptionsName : null, (0, default_context_name_1.defaultContextName)() !== modelOptionsName && modelOptionsName ? modelOptionsName : null, String(propertyOptions.name || propertyOptions.originalName), ] .filter(Boolean) .map((v) => { v = (0, case_anything_1.constantCase)(v); for (const word of exports.CLEAR_WORDS) { v = v.replace(word, ''); } return v; }) .join('_'); return prepareFullname.split('_').filter(Boolean).join('_'); } } exports.DotEnvPropertyNameFormatter = DotEnvPropertyNameFormatter; //# sourceMappingURL=dot-env-property-name.formatter.js.map