@sitecore/sc-contenthub-webclient-sdk
Version:
Sitecore Content Hub WebClient SDK.
31 lines • 961 B
JavaScript
import { InvalidOperationError } from "../errors/invalid-operation-error";
export 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 InvalidOperationError("Can't deserialize falsy value.");
}
else if (typeof value !== "string") {
throw new 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;
}
}
//# sourceMappingURL=string-to-any-map-converter.js.map