UNPKG

@svta/common-media-library

Version:
46 lines 1.13 kB
import { symbolToStr } from '../cta/utils/symbolToStr.js'; import { SfItem } from '../structuredfield/SfItem.js'; import { decodeSfDict } from '../structuredfield/decodeSfDict.js'; function reduceValue(value) { if (Array.isArray(value)) { return value.map(reduceValue); } if (typeof value === 'symbol') { return symbolToStr(value); } if (value instanceof SfItem && !value.params) { return reduceValue(value.value); } if (typeof value === 'string') { return decodeURIComponent(value); } return value; } ; /** * Decode a CMCD string to an object. * * @param cmcd - The CMCD string to decode. * * @returns The decoded CMCD object. * * @group CMCD * * @beta * * @example * {@includeCode ../../test/cmcd/decodeCmcd.test.ts#example} */ export function decodeCmcd(cmcd) { if (!cmcd) { return {}; } const sfDict = decodeSfDict(cmcd); return Object .entries(sfDict) .reduce((acc, [key, item]) => { acc[key] = reduceValue(item.value); return acc; }, {}); } //# sourceMappingURL=decodeCmcd.js.map