UNPKG

@boostercloud/cli

Version:

CLI of the Booster Framework, the next level of abstraction for cloud-native applications

36 lines (35 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.classNameToFileName = classNameToFileName; exports.fileNameWithExtension = fileNameWithExtension; exports.checkResourceNameIsValid = checkResourceNameIsValid; const inflected = require("inflected"); function classNameToFileName(name) { return inflected.dasherize(inflected.underscore(name)); } function fileNameWithExtension(name, extension = 'ts') { return (classNameToFileName(name) + '.' + extension).toLowerCase(); } function checkResourceNameIsValid(name) { if (!hasValidResourceName(name)) throw new Error(`'${name}' is not valid resource name. Please use PascalCase name with valid characters.`); } function hasValidResourceName(name) { const resourceName = formatResourceName(name); return resourceName === name; } function formatResourceName(name) { const resourceName = name .replace(/^[\d-]|[#$-/:-?{-~!"^_`[\]]/g, ' ') .replace(/\s+/g, ' ') .trim(); if (resourceName === '') return null; if (resourceName.length === 1) return resourceName.toLocaleUpperCase(); const match = resourceName.match(/[a-zA-Z\d]+/g); if (match) return match.map(titleCaseString).join(''); return resourceName; } const titleCaseString = (value) => value[0].toLocaleUpperCase() + value.slice(1);