UNPKG

@svta/common-media-library

Version:
49 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeCmcd = decodeCmcd; const symbolToStr_js_1 = require("../cta/utils/symbolToStr.js"); const SfItem_js_1 = require("../structuredfield/SfItem.js"); const decodeSfDict_js_1 = require("../structuredfield/decodeSfDict.js"); function reduceValue(value) { if (Array.isArray(value)) { return value.map(reduceValue); } if (typeof value === 'symbol') { return (0, symbolToStr_js_1.symbolToStr)(value); } if (value instanceof SfItem_js_1.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} */ function decodeCmcd(cmcd) { if (!cmcd) { return {}; } const sfDict = (0, decodeSfDict_js_1.decodeSfDict)(cmcd); return Object .entries(sfDict) .reduce((acc, [key, item]) => { acc[key] = reduceValue(item.value); return acc; }, {}); } //# sourceMappingURL=decodeCmcd.js.map