UNPKG

@svta/common-media-library

Version:
38 lines 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toCmcdHeaders = toCmcdHeaders; const encodeSfDict_js_1 = require("../structuredfield/encodeSfDict.js"); const groupCmcdHeaders_js_1 = require("./groupCmcdHeaders.js"); const prepareCmcdData_js_1 = require("./prepareCmcdData.js"); /** * Convert a CMCD data object to request headers * * @param cmcd - The CMCD data object to convert. * @param options - Options for encoding the CMCD object. * * @returns The CMCD header shards. * * @group CMCD * * @beta * * @example * {@includeCode ../../test/cmcd/toCmcdHeaders.test.ts#example} */ function toCmcdHeaders(cmcd, options = {}) { const result = {}; if (!cmcd) { return result; } const data = (0, prepareCmcdData_js_1.prepareCmcdData)(cmcd, options); const shards = (0, groupCmcdHeaders_js_1.groupCmcdHeaders)(data, options === null || options === void 0 ? void 0 : options.customHeaderMap); return Object.entries(shards) .reduce((acc, [field, value]) => { const shard = (0, encodeSfDict_js_1.encodeSfDict)(value, { whitespace: false }); if (shard) { acc[field] = shard; } return acc; }, result); } //# sourceMappingURL=toCmcdHeaders.js.map