UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

35 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringToAnyMapConverter = void 0; const invalid_operation_error_1 = require("../errors/invalid-operation-error"); class StringToAnyMapConverter { /** * Serializes an object into a JsonValue. * * @param value - An object * * @returns A Json Value. */ serialize(value) { return JSON.stringify(value); } /** * Deserializes a JsonValue into an object. * * @param value - A Json Value * * @returns An object. */ deserialize(value) { if (!value) { throw new invalid_operation_error_1.InvalidOperationError("Can't deserialize falsy value."); } else if (typeof value !== "string") { throw new invalid_operation_error_1.InvalidOperationError(`Expected a value of type 'string', but value was of type '${typeof value}'.`); } const obj = typeof value === "string" ? JSON.parse(value) : JSON.parse(JSON.stringify(value)); return obj; } } exports.StringToAnyMapConverter = StringToAnyMapConverter; //# sourceMappingURL=string-to-any-map-converter.js.map