UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

43 lines 1.56 kB
import { TaJson } from "ta-json"; import { PageComponentResource } from "../models/pages/page-component-resource"; export class PageResourceZonesConverter { /** * Serializes a string map of arrays of {@link PageComponentResource}s. * * @param value - The map of strings to arrays of {@link PageComponentResource}s * @returns A JSON value object. */ serialize(value) { const result = {}; Object.keys(value).forEach(zoneName => { const zone = value[zoneName]; result[zoneName] = zone.map(pageComponentResource => { // eslint-disable-next-line @typescript-eslint/no-unsafe-return return TaJson.serialize(pageComponentResource); }); }); return result; } /** * Deserializes a JSON object into a string map of arrays of {@link PageComponentResource}s. * * @param value - A JSON object * @returns A mapping of strings to arrays of {@link PageComponentResource}s. */ deserialize(value) { if (!value) { return {}; } const result = {}; Object.keys(value).forEach(zoneName => { const zone = value[zoneName]; if (Array.isArray(zone)) { result[zoneName] = zone.map(pageComponentResource => { return TaJson.deserialize(pageComponentResource, PageComponentResource); }); } }); return result; } } //# sourceMappingURL=page-resource-zones-converter.js.map