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

omniclone

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

omniclone - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

2

dist/main.js

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

module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){const o=r(1);e.exports=function(e={},{setPrototype:t=!1,invokeConstructors:r=!0,copyNonEnumerables:n=!1,copySymbols:i=!1,copyGettersSetters:s=!1,allowCircularReferences:c=!1,discardErrorObjects:f=!0}={}){if(!e||"object"!=typeof e)throw new TypeError("TypeError: invalid 'obj' argument's type");if(e instanceof Number||e instanceof String||e instanceof Boolean)return null;if(e instanceof Promise||e instanceof WeakMap||e instanceof WeakSet)return e;if(e instanceof Error){if(f)return null;throw new TypeError("TypeError: cannot copy Error objects")}if(e instanceof RegExp){const{source:t,flags:r,lastIndex:o}=e,n=new RegExp(t,r);return n.lastIndex=o,n}if(e instanceof Date)return new Date(e.getTime());if("boolean"!=typeof t)throw new TypeError("TypeError: invalid 'setPrototype' flag's type");if("boolean"!=typeof r)throw new TypeError("TypeError: invalid 'invokeConstructors' flag's type");if("boolean"!=typeof n)throw new TypeError("TypeError: invalid 'copyNonEnumerables' flag's type");if("boolean"!=typeof i)throw new TypeError("TypeError: invalid 'copySymbols' flag's type");if("boolean"!=typeof s)throw new TypeError("TypeError: invalid 'copyGettersSetters' flag's type");if("boolean"!=typeof c)throw new TypeError("TypeError: invalid 'allowCircularReferences' flag's type");if("boolean"!=typeof f)throw new TypeError("TypeError: invalid 'discardErrorObjects' flag's type");return o(e,{setPrototype:t,invokeConstructors:r,copyNonEnumerables:n,copySymbols:i,copyGettersSetters:s,allowCircularReferences:c,discardErrorObjects:f})}},function(e,t){e.exports=function(e,t){const r=new WeakMap,o=e;function n(e,t,r,n){return function(e,t,r,n,s){const{copyNonEnumerables:c,copySymbols:f,copyGettersSetters:a,allowCircularReferences:u,discardErrorObjects:l}=r;if(Array.isArray(t))for(const[c,f]of t)if(f&&"object"==typeof f){if(n.has(f)){e.set(c,n.get(f));continue}if(s.has(f)){if(u){e.set(c,s.get(f));continue}throw new TypeError("TypeError: circular reference found")}if(f instanceof Error){if(l)continue;throw new TypeError("TypeError: cannot copy Error objects")}if(f instanceof Number||f instanceof Boolean){e.set(c,f.valueOf());continue}if(f instanceof String){e.set(c,f.toString());continue}if(f instanceof Date){e.set(c,new Date(f.getTime())),n.set(f,e.get(c));continue}if(f instanceof RegExp){const{lastIndex:t}=f,r=new RegExp(f.source,f.flags);r.lastIndex=t,e.set(c,r),n.set(f,e.get(c));continue}if(f instanceof Promise){e.set(c,f);continue}if(f instanceof WeakMap){e.set(c,f);continue}if(f instanceof WeakSet){e.set(c,f);continue}e.set(c,i(f,r,s,o)),n.set(f,e.get(c))}else e.set(c,f);Object.entries(t).forEach(([t,p])=>{const{value:y,enumerable:b}=p;if((c||b)&&(f||"symbol"!=typeof y)&&(a||!p.get&&!p.set))if(y&&"object"==typeof y){if(n.has(y))return void(e[t]=n.get(y));if(s.has(y)){if(u)return void(e[t]=s.get(y));throw new TypeError("TypeError: circular reference found")}if(y instanceof Error){if(l)return;throw new TypeError("TypeError: cannot copy Error objects")}if(y instanceof Number||y instanceof Boolean){const r=p.value.valueOf();return void Object.defineProperty(e,t,{...p,...{value:r}})}if(y instanceof String){const r=p.value.toString();return void Object.defineProperty(e,t,{...p,...{value:r}})}if(y instanceof Date){const r=new Date(p.value.getTime());return Object.defineProperty(e,t,{...p,...{value:r}}),void n.set(y,e[t])}if(y instanceof RegExp){const{value:{lastIndex:r}}=p,o=new RegExp(p.value.source,p.value.flags);return Object.defineProperty(e,t,{...p,...{value:o}}),e[t].lastIndex=r,void n.set(y,e[t])}if(y instanceof Promise)return void Object.defineProperty(e,t,p);if(y instanceof WeakMap)return void Object.defineProperty(e,t,p);if(y instanceof WeakSet)return void Object.defineProperty(e,t,p);e[t]=i(y,r,s,o),n.set(y,e[t])}else{const r=Object.getOwnPropertyDescriptor(e,t);r&&!r.configurable||Object.defineProperty(e,t,p)}})}(e,t,r,new WeakMap,n)}function i(e,t,r,o){const{setPrototype:i,invokeConstructors:s,allowCircularReferences:c}=t;r.set(e,e);let f=null;return f=s?new e.constructor:i?Object.create(Object.getPrototypeOf(e)):{},e instanceof Map?n(f,[...e.entries()],t,r):n(f,Object.getOwnPropertyDescriptors(e),t,r),c&&(r.set(e,f),o===e&&function(e,t){const r=new WeakMap;r.set(e),function e(t,r,o){if(t instanceof Map){const n=[...t.entries()];for(const[i,s]of n)if(s&&"object"==typeof s)if(r.has(s))t.set(i,r.get(s));else{if(o.has(s))continue;o.set(s),e(s,r,o)}}else Object.entries(t).forEach(([n,i])=>{if(i&&"object"==typeof i)if(r.has(i))t[n]=r.get(i);else{if(o.has(i))return;o.set(i),e(i,r,o)}})}(e,t,r)}(f,r)),f}return i(e,t,r,o)}}]);
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){const n=r(1);e.exports=function(e={},{setPrototype:t=!1,invokeConstructors:r=!0,copyNonEnumerables:o=!1,copySymbols:i=!1,copyGettersSetters:s=!1,allowCircularReferences:c=!1,discardErrorObjects:f=!0}={}){if(!e||"object"!=typeof e)throw new TypeError("TypeError: invalid 'obj' argument's type");if(e instanceof Number||e instanceof String||e instanceof Boolean)return null;if(e instanceof Promise||e instanceof WeakMap||e instanceof WeakSet)return e;if(e instanceof Error){if(f)return null;throw new TypeError("TypeError: cannot copy Error objects")}if(e instanceof RegExp){const{source:t,flags:r,lastIndex:n}=e,o=new RegExp(t,r);return o.lastIndex=n,o}if(e instanceof Date)return new Date(e.getTime());if("boolean"!=typeof t)throw new TypeError("TypeError: invalid 'setPrototype' flag's type");if("boolean"!=typeof r)throw new TypeError("TypeError: invalid 'invokeConstructors' flag's type");if("boolean"!=typeof o)throw new TypeError("TypeError: invalid 'copyNonEnumerables' flag's type");if("boolean"!=typeof i)throw new TypeError("TypeError: invalid 'copySymbols' flag's type");if("boolean"!=typeof s)throw new TypeError("TypeError: invalid 'copyGettersSetters' flag's type");if("boolean"!=typeof c)throw new TypeError("TypeError: invalid 'allowCircularReferences' flag's type");if("boolean"!=typeof f)throw new TypeError("TypeError: invalid 'discardErrorObjects' flag's type");return n(e,{setPrototype:t,invokeConstructors:r,copyNonEnumerables:o,copySymbols:i,copyGettersSetters:s,allowCircularReferences:c,discardErrorObjects:f})}},function(e,t){e.exports=function(e,t){const r=new WeakMap,n=e;function o(e,t,r,o){return function(e,t,r,o,s){const{copyNonEnumerables:c,copySymbols:f,copyGettersSetters:a,allowCircularReferences:u,discardErrorObjects:p}=r,{mapEntries:l,setEntries:y,ownPropsDcps:d}=t;if(l)for(const[t,c]of l)if(c&&"object"==typeof c){if(o.has(c)){e.set(t,o.get(c));continue}if(s.has(c)){if(u){e.set(t,s.get(c));continue}throw new TypeError("TypeError: circular reference found")}if(c instanceof Error){if(p)continue;throw new TypeError("TypeError: cannot copy Error objects")}if(c instanceof Number||c instanceof Boolean){e.set(t,c.valueOf());continue}if(c instanceof String){e.set(t,c.toString());continue}if(c instanceof Date){e.set(t,new Date(c.getTime())),o.set(c,e.get(t));continue}if(c instanceof RegExp){const{lastIndex:r}=c,n=new RegExp(c.source,c.flags);n.lastIndex=r,e.set(t,n),o.set(c,e.get(t));continue}if(c instanceof Promise){e.set(t,c);continue}if(c instanceof WeakMap){e.set(t,c);continue}if(c instanceof WeakSet){e.set(t,c);continue}e.set(t,i(c,r,s,n)),o.set(c,e.get(t))}else e.set(t,c);else if(y)for(const t of y)if(t&&"object"==typeof t){if(s.has(t)){if(u){e.add(s.get(t));continue}throw new TypeError("TypeError: circular reference found")}if(t instanceof Error){if(p)continue;throw new TypeError("TypeError: cannot copy Error objects")}if(t instanceof Number||t instanceof Boolean){e.add(t.valueOf());continue}if(t instanceof String){e.add(t.toString());continue}if(t instanceof Date){const r=new Date(t.getTime());e.add(r);continue}if(t instanceof RegExp){const{lastIndex:r}=t,n=new RegExp(t.source,t.flags);n.lastIndex=r,e.add(n);continue}if(t instanceof Promise){e.add(t);continue}if(t instanceof WeakMap){e.add(t);continue}if(t instanceof WeakSet){e.add(t);continue}const o=i(t,r,s,n);e.add(o)}else e.add(t);else Object.entries(d).forEach(([t,l])=>{const{value:y,enumerable:d}=l;if((c||d)&&(f||"symbol"!=typeof y)&&(a||!l.get&&!l.set))if(y&&"object"==typeof y){if(o.has(y))return void(e[t]=o.get(y));if(s.has(y)){if(u)return void(e[t]=s.get(y));throw new TypeError("TypeError: circular reference found")}if(y instanceof Error){if(p)return;throw new TypeError("TypeError: cannot copy Error objects")}if(y instanceof Number||y instanceof Boolean){const r=l.value.valueOf();return void Object.defineProperty(e,t,{...l,...{value:r}})}if(y instanceof String){const r=l.value.toString();return void Object.defineProperty(e,t,{...l,...{value:r}})}if(y instanceof Date){const r=new Date(l.value.getTime());return Object.defineProperty(e,t,{...l,...{value:r}}),void o.set(y,e[t])}if(y instanceof RegExp){const{value:{lastIndex:r}}=l,n=new RegExp(l.value.source,l.value.flags);return Object.defineProperty(e,t,{...l,...{value:n}}),e[t].lastIndex=r,void o.set(y,e[t])}if(y instanceof Promise)return void Object.defineProperty(e,t,l);if(y instanceof WeakMap)return void Object.defineProperty(e,t,l);if(y instanceof WeakSet)return void Object.defineProperty(e,t,l);e[t]=i(y,r,s,n),o.set(y,e[t])}else{const r=Object.getOwnPropertyDescriptor(e,t);r&&!r.configurable||Object.defineProperty(e,t,l)}})}(e,t,r,new WeakMap,o)}function i(e,t,r,n){const{setPrototype:i,invokeConstructors:s,allowCircularReferences:c}=t;r.set(e,e);let f=null;return f=s?new e.constructor:i?Object.create(Object.getPrototypeOf(e)):{},e instanceof Map?o(f,{mapEntries:[...e.entries()]},t,r):e instanceof Set?o(f,{setEntries:[...e.values()]},t,r):o(f,{ownPropsDcps:Object.getOwnPropertyDescriptors(e)},t,r),c&&(r.set(e,f),n===e&&function(e,t){const r=new WeakMap;r.set(e),function e(t,r,n){if(t instanceof Map){const o=[...t.entries()];for(const[i,s]of o)if(s&&"object"==typeof s)if(r.has(s))t.set(i,r.get(s));else{if(n.has(s))continue;n.set(s),e(s,r,n)}}else if(t instanceof Set){const o=[...t.values()];for(const i of o)if(i&&"object"==typeof i)if(r.has(i))t.delete(i),t.add(r.get(i));else{if(n.has(i))continue;n.set(i),e(i,r,n)}}else Object.entries(t).forEach(([o,i])=>{if(i&&"object"==typeof i)if(r.has(i))t[o]=r.get(i);else{if(n.has(i))return;n.set(i),e(i,r,n)}})}(e,t,r)}(f,r)),f}return i(e,t,r,n)}}]);
{
"name": "omniclone",
"version": "0.4.1",
"version": "0.5.0",
"description": "deep cloning function for js objects",

@@ -5,0 +5,0 @@ "main": "dist/main.js",

@@ -32,5 +32,5 @@ # omniclone

4. let you to copy getters and setters, non enumerables properties and also symbols (customizable behavior)
5. correct handling of String, Boolean, Number, Error, Promise, Map, WeakMap and WeakSet objects
5. correct handling of String, Boolean, Number, Error, Promise, Map, Set, WeakMap and WeakSet objects
6. safe similar sibilings references are not duplicated
7. correct cloning of Array objects (if the `invokeConstructors` flag is setted)
7. correct cloning of Array objects
8. correct cloning of RegExp and Date objects

@@ -69,3 +69,5 @@

It is actually a default enabled setting, but you can disable it (loosing the ability to properly copy arrays).\
It is actually a default enabled setting, but you can disable it (loosing the ability to properly clone array, map and set objects).\
__It is highly discouraged to disable this flag__, do it only if you know what you are doing.
If the `invokeConstructors` flag is setted to `false`, a plain new object will be created for each object prop and for the resulting object as well. So the `constructor` prop will be set to the `Object` function, and the `[[Prototype]]` prop will be `Object.prototype`.\

@@ -173,3 +175,3 @@ Unless you use the `setPrototype` flag.

## what about String, Boolean, Number, Error, Promise, Map, WeakMap and WeakSet objects?
## what about String, Boolean, Number, Error, Promise, Map, Set, WeakMap and WeakSet objects?

@@ -185,5 +187,6 @@ String, Boolean and Number objects passed to `omniclone` as sources will produce `null`.\

Promise, WeakMap and WeakSet objects will be returned if passed to `omniclone` as sources.\
Promise, WeakMap and WeakSet objects props will be shallow copied.
Promise, WeakMap and WeakSet objects props will be copied by reference.
Map objects will be deeply cloned following same rules of normal objects.
Set objects will be deeply cloned following same rules of normal objects.

@@ -210,2 +213,1 @@ ## what about the 6th strength?

4. currently there is no isomorphic way to detect if an object is a `Proxy` nor is possible to access the handler object. Because of transparent virtualization, `omniclone` will copy each properties, the `constructor` and the `[[Prototype]]` directly from the proxed object.
5. currenlty there is a lack of support for Set objects. I'm working on this.
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