@sitecore/sc-contenthub-webclient-sdk
Version:
Sitecore Content Hub WebClient SDK.
40 lines • 1.32 kB
JavaScript
import { InvalidOperationError } from "../errors/invalid-operation-error";
import { FileVersion } from "../fileversion";
export 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 InvalidOperationError("Can't serialize falsy value.");
}
else if (!this.isFileVersion(version)) {
throw new 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 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}'.`);
}
return FileVersion.parse(value);
}
}
//# sourceMappingURL=file-version-converter.js.map