'use strict'; var _objectSpread = require("@babel/runtime-corejs3/helpers/objectSpread2")["default"]; var _Set2 = require("@babel/runtime-corejs3/core-js-stable/set"); var _Array$from = require("@babel/runtime-corejs3/core-js-stable/array/from"); var _Map2 = require("@babel/runtime-corejs3/core-js-stable/map"); var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map"); var _assertThisInitialized = require("@babel/runtime-corejs3/helpers/assertThisInitialized")["default"]; var _classPrivateFieldInitSpec = require("@babel/runtime-corejs3/helpers/classPrivateFieldInitSpec")["default"]; var _classPrivateFieldGet = require("@babel/runtime-corejs3/helpers/classPrivateFieldGet")["default"]; var _classPrivateFieldSet = require("@babel/runtime-corejs3/helpers/classPrivateFieldSet")["default"]; var _createClass = require("@babel/runtime-corejs3/helpers/createClass")["default"]; var _classCallCheck = require("@babel/runtime-corejs3/helpers/classCallCheck")["default"]; var _inherits = require("@babel/runtime-corejs3/helpers/inherits")["default"]; var _createSuper = require("@babel/runtime-corejs3/helpers/createSuper")["default"]; var _wrapNativeSuper = require("@babel/runtime-corejs3/helpers/wrapNativeSuper")["default"]; var SerializerError = function (_Error) { _inherits(SerializerError, _Error); var _super = _createSuper(SerializerError); function SerializerError() { _classCallCheck(this, SerializerError); return _super.apply(this, arguments); } return _createClass(SerializerError); }(_wrapNativeSuper(Error)); var _serializerType = new _WeakMap(); var Serializer = function () { function Serializer(serializerType) { _classCallCheck(this, Serializer); _classPrivateFieldInitSpec(this, _serializerType, { writable: true, value: void 0 }); if (this.constructor === Serializer) { throw new SerializerError('This is an abstract class'); } _classPrivateFieldSet(this, _serializerType, serializerType); } _createClass(Serializer, [{ key: "getSerializerType", value: function getSerializerType() { return _classPrivateFieldGet(this, _serializerType); } }, { key: "serialize", value: function serialize(unserializedData) {} }, { key: "parse", value: function parse(serializedData) {} }]); return Serializer; }(); var _Set = new _WeakMap(); var SetSerializer = function (_Serializer) { _inherits(SetSerializer, _Serializer); var _super2 = _createSuper(SetSerializer); function SetSerializer() { var _this; _classCallCheck(this, SetSerializer); _this = _super2.call(this, 'Set'); _classPrivateFieldInitSpec(_assertThisInitialized(_this), _Set, { writable: true, value: void 0 }); try { _classPrivateFieldSet(_assertThisInitialized(_this), _Set, eval("new Set().constructor")); } catch (err) { _classPrivateFieldSet(_assertThisInitialized(_this), _Set, new _Set2().constructor); } return _this; } _createClass(SetSerializer, [{ key: "serialize", value: function serialize(unserializedData) { var serializedData = { value: _Array$from(unserializedData) }; return serializedData; } }, { key: "parse", value: function parse(serializedData) { var value = serializedData.value; var parsedData = new (_classPrivateFieldGet(this, _Set))(value); return parsedData; } }]); return SetSerializer; }(Serializer); var _Map = new _WeakMap(); var MapSerializer = function (_Serializer2) { _inherits(MapSerializer, _Serializer2); var _super3 = _createSuper(MapSerializer); function MapSerializer() { var _this2; _classCallCheck(this, MapSerializer); _this2 = _super3.call(this, 'Map'); _classPrivateFieldInitSpec(_assertThisInitialized(_this2), _Map, { writable: true, value: void 0 }); try { _classPrivateFieldSet(_assertThisInitialized(_this2), _Map, eval("new Map().constructor")); } catch (err) { _classPrivateFieldSet(_assertThisInitialized(_this2), _Map, new _Map2().constructor); } return _this2; } _createClass(MapSerializer, [{ key: "serialize", value: function serialize(unserializedData) { var serializedData = { value: _Array$from(unserializedData) }; return serializedData; } }, { key: "parse", value: function parse(serializedData) { var value = serializedData.value; var parsedData = new (_classPrivateFieldGet(this, _Map))(value); return parsedData; } }]); return MapSerializer; }(Serializer); var FunctionSerializer = function (_Serializer3) { _inherits(FunctionSerializer, _Serializer3); var _super4 = _createSuper(FunctionSerializer); function FunctionSerializer() { _classCallCheck(this, FunctionSerializer); return _super4.call(this, 'function'); } _createClass(FunctionSerializer, [{ key: "serialize", value: function serialize(unserializedData) { var serializedData = { value: "(".concat(unserializedData.toString(), ")") }; return serializedData; } }, { key: "parse", value: function parse(serializedData) { var value = serializedData.value; var parsedData = eval(value); return parsedData; } }]); return FunctionSerializer; }(Serializer); var DateSerializer = function (_Serializer4) { _inherits(DateSerializer, _Serializer4); var _super5 = _createSuper(DateSerializer); function DateSerializer() { _classCallCheck(this, DateSerializer); return _super5.call(this, 'Date'); } _createClass(DateSerializer, [{ key: "serialize", value: function serialize(unserializedData) { var serializedData = { value: unserializedData.toJSON() }; return serializedData; } }, { key: "parse", value: function parse(serializedData) { var value = serializedData.value; var parsedData = new Date(value); return parsedData; } }]); return DateSerializer; }(Serializer); var BigIntSerializer = function (_Serializer5) { _inherits(BigIntSerializer, _Serializer5); var _super6 = _createSuper(BigIntSerializer); function BigIntSerializer() { _classCallCheck(this, BigIntSerializer); return _super6.call(this, 'bigint'); } _createClass(BigIntSerializer, [{ key: "serialize", value: function serialize(unserializedData) { var serializedData = { value: unserializedData.toString() }; return serializedData; } }, { key: "parse", value: function parse(serializedData) { var value = serializedData.value; var parsedData = BigInt(value); return parsedData; } }]); return BigIntSerializer; }(Serializer); var _serializers = new _WeakMap(); var Installer = function () { function Installer(serializers) { _classCallCheck(this, Installer); _classPrivateFieldInitSpec(this, _serializers, { writable: true, value: void 0 }); _classPrivateFieldSet(this, _serializers, serializers); } _createClass(Installer, [{ key: "install", value: function install(serializerHandler, installOptions) { var serializers = _classPrivateFieldGet(this, _serializers); var options = _objectSpread({ includeFunctionSerializer: false }, installOptions); var includeFunctionSerializer = options.includeFunctionSerializer; for (var key in serializers) { var _Serializer6 = serializers[key]; var serializer = new _Serializer6(); var serializerType = serializer.getSerializerType(); if (serializerType !== 'function' || includeFunctionSerializer) { serializerHandler.addSerializer(serializer); } } } }]); return Installer; }(); var serializers = {}; serializers["SetSerializer"] = SetSerializer; serializers["MapSerializer"] = MapSerializer; serializers["FunctionSerializer"] = FunctionSerializer; serializers["DateSerializer"] = DateSerializer; serializers["BigIntSerializer"] = BigIntSerializer; var baseSerializersInstaller = new Installer(serializers); exports.BigIntSerializer = BigIntSerializer; exports.DateSerializer = DateSerializer; exports.FunctionSerializer = FunctionSerializer; exports.MapSerializer = MapSerializer; exports.SetSerializer = SetSerializer; exports.baseSerializersInstaller = baseSerializersInstaller; //# sourceMappingURL=index.cjs.map