liveperson-functions-cli
Version:
LivePerson Functions CLI
48 lines • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatDate = exports.transformToCSV = exports.validateFunctionDescription = exports.validateFunctionName = exports.parseInput = void 0;
const moment = require("moment-timezone");
const constants_1 = require("./constants");
function parseInput(flags, argv) {
const parsedFlags = [];
Object.keys(flags).forEach((e) => {
parsedFlags.push(`--${flags[e].name}`);
parsedFlags.push(`-${flags[e].char}`);
});
return argv.filter((arg) => !parsedFlags.includes(arg));
}
exports.parseInput = parseInput;
function validateFunctionName(functionName) {
if (/^\w+$/.test(functionName)) {
return true;
}
return 'Invalid name only A-Z, 0-9, _ allowed!';
}
exports.validateFunctionName = validateFunctionName;
function validateFunctionDescription(description) {
if (description !== '') {
return true;
}
return 'Description cannot be empty!';
}
exports.validateFunctionDescription = validateFunctionDescription;
function transformToCSV(metrics, headerLabels) {
const replacer = (_, value) => (value === null ? '' : value);
const headers = Object.keys(metrics[0]);
const csv = [
headerLabels
? headers.map((header) => headerLabels[header] || 'MISSING HEADER LABEL')
: headers.join(','),
...metrics.map((row) => headers
.map((fieldName) => JSON.stringify(row[fieldName], replacer))
.join(',')),
].join('\r\n');
return csv;
}
exports.transformToCSV = transformToCSV;
function formatDate(date) {
const timezone = moment.tz.guess(true);
return moment(date).tz(timezone).format(constants_1.DEFAULT_FORMAT_DATETIME_WITH_SECONDS);
}
exports.formatDate = formatDate;
//# sourceMappingURL=utils.js.map