UNPKG

unserializable

Version:

Utilities for converting unserializable JavaScript objects and instances to serializable objects and vice versa.

200 lines (167 loc) 4.63 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["Unserializable"] = factory(); else root["Unserializable"] = factory(); })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports) { 'use strict'; exports.__esModule = true; exports.getType = getType; var unserializable = { Map: (function (_Map) { function Map(_x) { return _Map.apply(this, arguments); } Map.toString = function () { return _Map.toString(); }; return Map; })(function (value) { return new Map(value); }), Set: (function (_Set) { function Set(_x2) { return _Set.apply(this, arguments); } Set.toString = function () { return _Set.toString(); }; return Set; })(function (value) { return new Set(value); }), Date: (function (_Date) { function Date(_x3) { return _Date.apply(this, arguments); } Date.toString = function () { return _Date.toString(); }; return Date; })(function (value) { return new Date(value); }), RegExp: (function (_RegExp) { function RegExp(_x4) { return _RegExp.apply(this, arguments); } RegExp.toString = function () { return _RegExp.toString(); }; return RegExp; })(function (value) { var lastSlash = value.lastIndexOf('/'); return new RegExp(value.slice(1, lastSlash), value.slice(lastSlash + 1)); }) }; exports.unserializable = unserializable; var serializable = { Map: function Map(value) { return Array.from(value); }, Set: function Set(value) { return Array.from(value); }, Date: function Date(value) { return value.getTime(); }, RegExp: function RegExp(value) { return value.toString(); } }; exports.serializable = serializable; var typeChecks = { Map: (function (_Map2) { function Map(_x5) { return _Map2.apply(this, arguments); } Map.toString = function () { return _Map2.toString(); }; return Map; })(function (value) { return value instanceof Map; }), Set: (function (_Set2) { function Set(_x6) { return _Set2.apply(this, arguments); } Set.toString = function () { return _Set2.toString(); }; return Set; })(function (value) { return value instanceof Set; }), Date: (function (_Date2) { function Date(_x7) { return _Date2.apply(this, arguments); } Date.toString = function () { return _Date2.toString(); }; return Date; })(function (value) { return value instanceof Date; }), RegExp: (function (_RegExp2) { function RegExp(_x8) { return _RegExp2.apply(this, arguments); } RegExp.toString = function () { return _RegExp2.toString(); }; return RegExp; })(function (value) { return value instanceof RegExp; }) }; function getType(value) { for (var type in typeChecks) { if (typeChecks[type](value)) { return type; } } } /***/ } /******/ ]) }); ;