UNPKG

@brasil-interface/cli

Version:
53 lines 1.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InputHelper = void 0; const fs_1 = __importDefault(require("fs")); class InputHelper { static isSerializedArray(arg) { if (typeof arg !== "string") { return false; } if (arg.trim().startsWith("[") && arg.trim().endsWith("]")) { try { const parsed = JSON.parse(arg); return Array.isArray(parsed); } catch (e) { return false; } } return false; } static isCommaSeparated(arg) { return arg.includes(","); } static getArrayFromArrayLike(arg) { if (this.isSerializedArray(arg)) { return JSON.parse(arg); } if (this.isCommaSeparated(arg)) { return arg.split(","); } return [arg]; } static getArrayFromInputAlternativesOrFail(cmdArg, options) { let input = ""; let array = []; if (cmdArg) { input = cmdArg; } else if (input) { input = fs_1.default.readFileSync(input, "utf8"); } else { throw new Error("PT-BR: Nenhum input válido fornecido. EN-US: No valid input provided."); } array = InputHelper.getArrayFromArrayLike(input); return array; } } exports.InputHelper = InputHelper; //# sourceMappingURL=input-helper.js.map