@svta/common-media-library
Version:
A common library for media playback in JavaScript
35 lines • 1.07 kB
JavaScript
import { encodeSfDict } from '../structuredfield/encodeSfDict.js';
import { groupCmcdHeaders } from './groupCmcdHeaders.js';
import { prepareCmcdData } from './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}
*/
export function toCmcdHeaders(cmcd, options = {}) {
const result = {};
if (!cmcd) {
return result;
}
const data = prepareCmcdData(cmcd, options);
const shards = groupCmcdHeaders(data, options === null || options === void 0 ? void 0 : options.customHeaderMap);
return Object.entries(shards)
.reduce((acc, [field, value]) => {
const shard = encodeSfDict(value, { whitespace: false });
if (shard) {
acc[field] = shard;
}
return acc;
}, result);
}
//# sourceMappingURL=toCmcdHeaders.js.map