UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

44 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileVersionConverter = void 0; const invalid_operation_error_1 = require("../errors/invalid-operation-error"); const fileversion_1 = require("../fileversion"); class FileVersionConverter { isFileVersion(arg) { return arg.major !== undefined; } /** * Serializes a FileVersion into a string. * * @param version - A FileVersion * * @returns A string. */ serialize(version) { if (!version) { throw new invalid_operation_error_1.InvalidOperationError("Can't serialize falsy value."); } else if (!this.isFileVersion(version)) { throw new invalid_operation_error_1.InvalidOperationError(`Expected a value of type 'FileVersion', but value was of type '${typeof version}'.`); } return version.toString(); } /** * Deserializes a string into a FileVersion instance. * * @param value - A string * * @returns A FileVersion instance or null. */ 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}'.`); } return fileversion_1.FileVersion.parse(value); } } exports.FileVersionConverter = FileVersionConverter; //# sourceMappingURL=file-version-converter.js.map