UNPKG

jest-allure2-reporter

Version:
43 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.keyedLink = keyedLink; const tslib_1 = require("tslib"); const handlebars_1 = tslib_1.__importDefault(require("handlebars")); const common_1 = require("../../common"); const utils_1 = require("../../../utils"); function keyedLink(value, type) { if (value == null) { return; } if (typeof value === 'string') { return linkFormatter(value); } const overrideType = createTypeOverride(type); if (typeof value === 'function') { return (0, common_1.compose2)(({ value }) => { return (0, utils_1.thruMaybePromise)(value, overrideType); }, value); } const links = (0, utils_1.asArray)(overrideType(value)); return (0, common_1.compose2)((0, common_1.appender)(links), ({ value }) => (0, utils_1.asArray)(value)); } function createTypeOverride(type) { return (links) => { for (const link of (0, utils_1.asArray)(links)) { link.type = type; } return links; }; } function linkFormatter(format) { const formatter = handlebars_1.default.compile(format); return ({ value }) => { return (0, utils_1.asArray)(value).map((link) => link.url ? link : { ...link, url: formatter(link), }); }; } //# sourceMappingURL=keyedLink.js.map