UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

67 lines (66 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringUtils = void 0; const tslib_1 = require("tslib"); const file_system_utils_1 = require("./file-system-utils"); const path = tslib_1.__importStar(require("path")); const safira_version_1 = require("../safira-globals/safira-version"); class StringUtils { static isNullOrEmpty(str) { return !str || str.trim().length === 0; } static removeDigits(str) { return str.replace(/\d/g, ""); } static onlyNumbers(str) { return str.replace(/\D/g, ""); } static kebabCaseToCamelCase(str) { if (!str || !str.includes("-")) return str; return str.toLowerCase().replace(/-([a-z])/g, g => g[1].toUpperCase()); } static camelCaseToKebabCase(str) { if (!str) return ""; return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); } static getFileExtension(fileName) { if (!fileName) return ""; return fileName.split(".").pop() ?? ""; } static getFullFileName(pathFile) { if (!path) return ""; return path.parse(pathFile).base ?? ""; } static getFileName(pathFile) { return path.parse(pathFile).name; } static capitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); } static removeLastFolderFromStringPath(path) { return path.slice(0, Math.max(0, path.lastIndexOf(file_system_utils_1.FileSystemUtils.getFileSeparator()))); } static replaceAll(str, find, replace) { return str.split(find).join(replace); } static getUserAgent() { return `@veecode-platform/safira-cli@${safira_version_1.SafiraVersion.version}`; } static removeComments(string) { return string.replace(/(\/\/.*)|(\/\*([\S\s]+?)\*\/)/gm, ""); } static removeMultiLineAndWhiteSpaces(string) { return string.replace(/\s\s+/g, "").trim(); } static encodeBase64(str) { return Buffer.from(str, "binary").toString("base64"); } static decodeBase64(str) { return Buffer.from(str, "base64").toString("binary"); } } exports.StringUtils = StringUtils;