Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@macfja/serializer

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@macfja/serializer - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

2

dist/index.js

@@ -1,1 +0,1 @@

!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self)["macfja-serializer"]={})}(this,(function(r){"use strict";var e=function(r,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])},e(r,t)};var t=function(){return t=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r},t.apply(this,arguments)};function n(r,e,t){if(t||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return r.concat(n||Array.prototype.slice.call(e))}var o=function(r){function t(){return null!==r&&r.apply(this,arguments)||this}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,r),t}(Error),i="#$@__constructor__",a="#$@__instance__",f="#$@__reference__",u={},c=new Set,s={};function l(r,e){if("string"==typeof r||"number"==typeof r&&!isNaN(r)&&Math.abs(r)!==1/0||null==r||"boolean"==typeof r)return r;var n=e.indexOf(r);if(-1!==n)return a+n;e.push(r);var o=e.length-1;if(r.constructor===Array){var u=r.map((function(r){return l(r,e)}));return u.unshift(f+o),u}if(r.constructor===Object){var y=Object.fromEntries(Object.entries(r).map((function(r){return[r[0],l(r[1],e)]})));return y[f]=o,y}c.add(r.constructor);var p={};p=Object.defineProperty(p,i,{value:r.constructor.name,enumerable:!0}),p=Object.defineProperty(p,f,{value:o,enumerable:!0});var b=function(r,e){if(!Object.keys(s).includes(r.constructor.name))return;return s[r.constructor.name].toPlain(r,(function(r){return l(r,e)}))}(r,e);return void 0!==b?t(t({},b),p):(Object.getOwnPropertyNames(r).forEach((function(t){Object.defineProperty(p,t,{value:l(r[t],e),enumerable:!0})})),p)}function y(r,e,t){var n;if("string"==typeof r&&0===r.indexOf(a))return t[p=parseInt(r.slice(a.length))];if("string"==typeof r||"number"==typeof r||null==r||"boolean"==typeof r)return r;if(r.constructor===Array){if(0===r.length)return[];var u=r.shift();if("string"!=typeof u||u.substring(0,f.length)!==f){if(0===Object.keys(t).length)return r.unshift(u),r;throw new o}var c=[];t[p=u.slice(f.length)]=c;for(var l=0;l<r.length;l++)c[l]=y(r[l],e,t);return c}if(r.constructor===Object){var p;if(null===(p=null!==(n=r[f])&&void 0!==n?n:null)){if(0===Object.keys(t).length)return r;throw new o}if(delete r[f],!Object.keys(r).includes(i)){c={};for(var b in t[p]=c,r)c[b]=y(r[b],e,t);return c}var d=r[i];delete r[i];var g=function(r,e,t,n){if(!Object.keys(s).includes(e))return;return s[e].fromPlain(r,(function(r){return y(r,t,n)}))}(r,d,e,t);if(void 0!==g)return g;if(!Object.keys(e).includes(d))throw new Error("The class "+d+" is not allowed");var v={};for(var b in t[p]=v,r)v[b]=y(r[b],e,t);return Object.setPrototypeOf(v,e[d].prototype),v}}function p(){c.clear()}function b(r){u[r.name]=r}function d(r,e,t){s[r]={toPlain:e,fromPlain:t}}!function(r,e){r("Date",(r=>({time:r.getTime()})),(function(r){let e=new Date;return e.setTime(r.time),e})),r("BigInt",(r=>({number:r.toString()})),(r=>BigInt(r.number))),r("String",(r=>({text:r.toString()})),(r=>new String(r.text))),r("RegExp",(r=>({source:r.source,flags:r.flags})),(r=>new RegExp(r.source,r.flags))),r("Number",(function(r){let e={nan:!1,infinity:!1,positive:!0,number:null};return Math.abs(r)===1/0?(e.infinity=!0,e.positive=Math.abs(r)===r,e):isNaN(r)?(e.nan=!0,e):(e.number=r.valueOf(),e)}),(function(r){return r.nan?NaN:r.infinity?1/0*(r.positive?1:-1):new Number(r.number)})),r("Map",((r,e)=>({data:Array.from(r.entries()).map((r=>e(r)))})),(function(r,e){const t=new Map;return r.data.map((r=>e(r))).forEach((([r,e])=>t.set(r,e))),t})),r("Set",((r,e)=>({data:Array.from(r.values()).map((r=>e(r)))})),(function(r,e){const t=new Set;return r.data.map((r=>e(r))).forEach((r=>t.add(r))),t})),r("ArrayBuffer",((r,e)=>({data:e(new Uint8Array(r))})),((r,e)=>e(r.data).buffer)),r("DataView",((r,e)=>({buffer:e(r.buffer),offset:r.byteOffset,length:r.byteLength})),((r,e)=>new DataView(e(r.buffer),r.offset,r.length))),[Error,EvalError,RangeError,AggregateError,ReferenceError,SyntaxError,TypeError,URIError,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array].forEach((r=>e(r)))}(d,b),r.addClassHandler=d,r.addGlobalAllowedClass=b,r.deserialize=function(r,e){if(void 0===e&&(e=void 0),"string"!=typeof r)return r;if(void 0===e&&(e={}),"undefined"!==r){e=Object.fromEntries(n(n([],Object.entries(e),!0),Object.entries(u),!0));try{return y(JSON.parse(r),e,{})}catch(e){return r}}},r.getCollectedClasses=function(r){void 0===r&&(r=!1);var e=Array.from(c);return r&&p(),e},r.resetCollectedClasses=p,r.serialize=function(r){return void 0===r?"undefined":JSON.stringify(l(r,[]))},r.setGlobalAllowedClasses=function(r,e){void 0===e&&(e=!1);var t={};r.constructor===Array&&(t=Object.fromEntries(r.map((function(r){return[r.name,r]})))),"object"==typeof r&&(t=r),u=e?Object.fromEntries(n(n([],Object.entries(u),!0),Object.entries(t),!0)):t},Object.defineProperty(r,"__esModule",{value:!0})}));
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self)["macfja-serializer"]={})}(this,(function(r){"use strict";var e=function(r,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])},e(r,t)};var t=function(){return t=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r},t.apply(this,arguments)};function n(r,e,t){if(t||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return r.concat(n||Array.prototype.slice.call(e))}var o=function(r){function t(){return null!==r&&r.apply(this,arguments)||this}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,r),t}(Error),i="#$@__constructor__",a="#$@__instance__",f="#$@__reference__",u={},c=new Set,s={};function l(r,e){if("string"==typeof r||"number"==typeof r&&!isNaN(r)&&Math.abs(r)!==1/0||null==r||"boolean"==typeof r)return r;var n=e.indexOf(r);if(-1!==n)return a+n;e.push(r);var o=e.length-1;if(r.constructor===Array){var u=r.map((function(r){return l(r,e)}));return u.unshift(f+o),u}if(r.constructor===Object){var y=Object.fromEntries(Object.entries(r).map((function(r){return[r[0],l(r[1],e)]})));return y[f]=o,y}c.add(r.constructor);var p={};p=Object.defineProperty(p,i,{value:r.constructor.name,enumerable:!0}),p=Object.defineProperty(p,f,{value:o,enumerable:!0});var b=function(r,e){if(!Object.keys(s).includes(r.constructor.name))return;return s[r.constructor.name].toPlain(r,(function(r){return l(r,e)}))}(r,e);return void 0!==b?t(t({},b),p):(Object.getOwnPropertyNames(r).forEach((function(t){Object.defineProperty(p,t,{value:l(r[t],e),enumerable:!0})})),p)}function y(r,e,t){var n;if("string"==typeof r&&0===r.indexOf(a))return t[p=parseInt(r.slice(a.length))];if("string"==typeof r||"number"==typeof r||null==r||"boolean"==typeof r)return r;if(r.constructor===Array){if(0===r.length)return[];var u=r.shift();if("string"!=typeof u||u.substring(0,f.length)!==f){if(0===Object.keys(t).length)return r.unshift(u),r;throw new o}var c=[];t[p=u.slice(f.length)]=c;for(var l=0;l<r.length;l++)c[l]=y(r[l],e,t);return c}if(r.constructor===Object){var p;if(null===(p=null!==(n=r[f])&&void 0!==n?n:null)){if(0===Object.keys(t).length)return r;throw new o}if(delete r[f],!Object.keys(r).includes(i)){c={};for(var b in t[p]=c,r)c[b]=y(r[b],e,t);return c}var d=r[i];delete r[i];var g=function(r,e,t,n){if(!Object.keys(s).includes(e))return;return s[e].fromPlain(r,(function(r){return y(r,t,n)}))}(r,d,e,t);if(void 0!==g)return g;if(!Object.keys(e).includes(d))throw new Error("The class "+d+" is not allowed");var v={};for(var b in t[p]=v,r)v[b]=y(r[b],e,t);return Object.setPrototypeOf(v,e[d].prototype),v}}function p(){c.clear()}function b(r){u[r.name]=r}function d(r,e,t){s[r]={toPlain:e,fromPlain:t}}!function(r,e){r("Date",(r=>({time:r.getTime()})),(function(r){let e=new Date;return e.setTime(r.time),e})),r("BigInt",(r=>({number:r.toString()})),(r=>BigInt(r.number))),r("String",(r=>({text:r.toString()})),(r=>new String(r.text))),r("RegExp",(r=>({source:r.source,flags:r.flags})),(r=>new RegExp(r.source,r.flags))),r("Number",(function(r){let e={nan:!1,infinity:!1,positive:!0,number:null};return Math.abs(r)===1/0?(e.infinity=!0,e.positive=Math.abs(r)===r,e):isNaN(r)?(e.nan=!0,e):(e.number=r.valueOf(),e)}),(function(r){return r.nan?NaN:r.infinity?1/0*(r.positive?1:-1):new Number(r.number)})),r("Map",((r,e)=>({data:Array.from(r.entries()).map((r=>e(r)))})),(function(r,e){const t=new Map;return r.data.map((r=>e(r))).forEach((([r,e])=>t.set(r,e))),t})),r("Set",((r,e)=>({data:Array.from(r.values()).map((r=>e(r)))})),(function(r,e){const t=new Set;return r.data.map((r=>e(r))).forEach((r=>t.add(r))),t})),r("ArrayBuffer",((r,e)=>({data:e(new Uint8Array(r))})),((r,e)=>e(r.data).buffer)),r("DataView",((r,e)=>({buffer:e(r.buffer),offset:r.byteOffset,length:r.byteLength})),((r,e)=>new DataView(e(r.buffer),r.offset,r.length))),["Error","EvalError","RangeError","AggregateError","ReferenceError","SyntaxError","TypeError","URIError","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].forEach((r=>{void 0!==global[r]&&e(global[r])}))}(d,b),r.addClassHandler=d,r.addGlobalAllowedClass=b,r.deserialize=function(r,e){if(void 0===e&&(e=void 0),"string"!=typeof r)return r;if(void 0===e&&(e={}),"undefined"!==r){e=Object.fromEntries(n(n([],Object.entries(e),!0),Object.entries(u),!0));try{return y(JSON.parse(r),e,{})}catch(e){return r}}},r.getCollectedClasses=function(r){void 0===r&&(r=!1);var e=Array.from(c);return r&&p(),e},r.resetCollectedClasses=p,r.serialize=function(r){return void 0===r?"undefined":JSON.stringify(l(r,[]))},r.setGlobalAllowedClasses=function(r,e){void 0===e&&(e=!1);var t={};r.constructor===Array&&(t=Object.fromEntries(r.map((function(r){return[r.name,r]})))),"object"==typeof r&&(t=r),u=e?Object.fromEntries(n(n([],Object.entries(u),!0),Object.entries(t),!0)):t},Object.defineProperty(r,"__esModule",{value:!0})}));
{
"name": "@macfja/serializer",
"version": "1.1.2",
"version": "1.1.3",
"description": "Transform any object, class, array, primitive to a serialized string and vice-versa",

@@ -23,2 +23,3 @@ "main": "./dist/index.js",

".": {
"types": "./types/index.d.ts",
"import": "./dist/index.mjs",

@@ -25,0 +26,0 @@ "require": "./dist/index.cjs"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc