UNPKG

@requestnetwork/multi-format

Version:
49 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.serialize = exports.deserialize = exports.plainFormat = exports.identityFormat = exports.hashFormat = exports.MultiFormatGroup = exports.encryptionFormats = void 0; const encryption_format_1 = require("./encryption/encryption-format"); Object.defineProperty(exports, "encryptionFormats", { enumerable: true, get: function () { return encryption_format_1.encryptionFormats; } }); const multi_format_group_1 = require("./multi-format-group"); Object.defineProperty(exports, "MultiFormatGroup", { enumerable: true, get: function () { return multi_format_group_1.MultiFormatGroup; } }); const hash_format_1 = require("./hash/hash-format"); Object.defineProperty(exports, "hashFormat", { enumerable: true, get: function () { return hash_format_1.hashFormat; } }); const identity_format_1 = require("./identity/identity-format"); Object.defineProperty(exports, "identityFormat", { enumerable: true, get: function () { return identity_format_1.identityFormat; } }); const plain_format_1 = require("./plain/plain-format"); Object.defineProperty(exports, "plainFormat", { enumerable: true, get: function () { return plain_format_1.plainFormat; } }); /** List of the groups of formats available */ const availableFormats = [ encryption_format_1.encryptionFormats, identity_format_1.identityFormat, hash_format_1.hashFormat, plain_format_1.plainFormat, ]; /** * Deserializes any supported serialized string * * @param formatted the string to deserialize * @returns the deserialized object or throw */ function deserialize(formatted) { const matchingFormat = availableFormats.find((format) => format.isDeserializableString(formatted)); if (matchingFormat) { return matchingFormat.deserialize(formatted); } throw new Error('No format found to deserialize this string'); } exports.deserialize = deserialize; /** * Serializes any supported serializable object * * @param data the object to serialize * @returns the serialized string or throw. */ function serialize(data) { const matchingFormat = availableFormats.find((format) => format.isSerializableObject(data)); if (matchingFormat) { return matchingFormat.serialize(data); } throw new Error('No format found to serialize this object'); } exports.serialize = serialize; //# sourceMappingURL=index.js.map