+50
-61
| 'use strict'; | ||
| // ES6 Map | ||
| var map; | ||
| try { | ||
| map = Map; | ||
| } catch (_) { } | ||
| var set; | ||
| function clone(src, seen) { | ||
| // Immutable things - null, undefined, functions, symbols, etc. | ||
| if (!src || typeof src !== 'object') return src; | ||
| // ES6 Set | ||
| try { | ||
| set = Set; | ||
| } catch (_) { } | ||
| // Things we've seen already (circular refs) | ||
| if (seen.has(src)) return seen.get(src); | ||
| function baseClone (src, circulars, clones) { | ||
| // Null/undefined/functions/etc | ||
| if (!src || typeof src !== 'object' || typeof src === 'function') { | ||
| return src | ||
| } | ||
| // Basic pattern for cloning something below here is: | ||
| // 1. Create copy | ||
| // 2. Add it to `seen` immediately, so we recognize it if we see it in | ||
| // subordinate members | ||
| // 3. clone subordinate members | ||
| // DOM Node | ||
| let copy; | ||
| if (src.nodeType && 'cloneNode' in src) { | ||
| return src.cloneNode(true) | ||
| // DOM Node | ||
| copy = src.cloneNode(true); | ||
| seen.set(src, copy); | ||
| } else if (src instanceof Date) { | ||
| // Date | ||
| copy = new Date(src.getTime()); | ||
| seen.set(src, copy); | ||
| } else if (src instanceof RegExp) { | ||
| // RegExp | ||
| copy = new RegExp(src); | ||
| seen.set(src, copy); | ||
| } else if (Array.isArray(src)) { | ||
| // Array | ||
| copy = new Array(src.length); | ||
| seen.set(src, copy); | ||
| for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen); | ||
| } else if (src instanceof Map) { | ||
| // Map | ||
| copy = new Map(); | ||
| seen.set(src, copy); | ||
| for (const [k, v] of src.entries()) copy.set(k, clone(v, seen)); | ||
| } else if (src instanceof Set) { | ||
| // Set | ||
| copy = new Set(); | ||
| seen.set(src, copy); | ||
| for (const v of src) copy.add(clone(v)); | ||
| } else if (src instanceof Object) { | ||
| // Object | ||
| copy = {}; | ||
| seen.set(src, copy); | ||
| for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen); | ||
| } else { | ||
| // Unrecognized thing. It's better to throw here than to return `src`, as | ||
| // we don't know whether src needs to be deep-copied here. | ||
| throw Error(`Unable to clone ${src}`); | ||
| } | ||
| // Date | ||
| if (src instanceof Date) { | ||
| return new Date(src.getTime()) | ||
| } | ||
| // RegExp | ||
| if (src instanceof RegExp) { | ||
| return new RegExp(src) | ||
| } | ||
| // Arrays | ||
| if (Array.isArray(src)) { | ||
| return src.map(clone) | ||
| } | ||
| // ES6 Maps | ||
| if (map && src instanceof map) { | ||
| return new Map(Array.from(src.entries())) | ||
| } | ||
| // ES6 Sets | ||
| if (set && src instanceof set) { | ||
| return new Set(Array.from(src.values())) | ||
| } | ||
| // Object | ||
| if (src instanceof Object) { | ||
| circulars.push(src); | ||
| var obj = Object.create(src); | ||
| clones.push(obj); | ||
| for (var key in src) { | ||
| var idx = circulars.findIndex(function (i) { | ||
| return i === src[key] | ||
| }); | ||
| obj[key] = idx > -1 ? clones[idx] : baseClone(src[key], circulars, clones); | ||
| } | ||
| return obj | ||
| } | ||
| // ??? | ||
| return src | ||
| return copy | ||
| } | ||
| function clone (src) { | ||
| return baseClone(src, [], []) | ||
| function index(src) { | ||
| return clone(src, new Map()) | ||
| } | ||
| module.exports = clone; | ||
| module.exports = index; |
+3
-2
| { | ||
| "name": "nanoclone", | ||
| "version": "0.2.1", | ||
| "version": "1.0.0", | ||
| "description": "300B to deep clone JavaScript objects", | ||
@@ -44,4 +44,5 @@ "license": "MIT", | ||
| "rollup": "^0.53.3", | ||
| "size-limit": "^0.13.2" | ||
| "size-limit": "^0.13.2", | ||
| "thrustcurve-db": "^0.3.14" | ||
| } | ||
| } |
+49
-60
@@ -1,69 +0,58 @@ | ||
| // ES6 Map | ||
| var map | ||
| try { | ||
| map = Map | ||
| } catch (_) { } | ||
| var set | ||
| function clone(src, seen) { | ||
| // Immutable things - null, undefined, functions, symbols, etc. | ||
| if (!src || typeof src !== 'object') return src; | ||
| // ES6 Set | ||
| try { | ||
| set = Set | ||
| } catch (_) { } | ||
| // Things we've seen already (circular refs) | ||
| if (seen.has(src)) return seen.get(src); | ||
| function baseClone (src, circulars, clones) { | ||
| // Null/undefined/functions/etc | ||
| if (!src || typeof src !== 'object' || typeof src === 'function') { | ||
| return src | ||
| } | ||
| // Basic pattern for cloning something below here is: | ||
| // 1. Create copy | ||
| // 2. Add it to `seen` immediately, so we recognize it if we see it in | ||
| // subordinate members | ||
| // 3. clone subordinate members | ||
| // DOM Node | ||
| let copy; | ||
| if (src.nodeType && 'cloneNode' in src) { | ||
| return src.cloneNode(true) | ||
| // DOM Node | ||
| copy = src.cloneNode(true); | ||
| seen.set(src, copy); | ||
| } else if (src instanceof Date) { | ||
| // Date | ||
| copy = new Date(src.getTime()); | ||
| seen.set(src, copy); | ||
| } else if (src instanceof RegExp) { | ||
| // RegExp | ||
| copy = new RegExp(src); | ||
| seen.set(src, copy); | ||
| } else if (Array.isArray(src)) { | ||
| // Array | ||
| copy = new Array(src.length); | ||
| seen.set(src, copy); | ||
| for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen); | ||
| } else if (src instanceof Map) { | ||
| // Map | ||
| copy = new Map(); | ||
| seen.set(src, copy); | ||
| for (const [k, v] of src.entries()) copy.set(k, clone(v, seen)); | ||
| } else if (src instanceof Set) { | ||
| // Set | ||
| copy = new Set(); | ||
| seen.set(src, copy); | ||
| for (const v of src) copy.add(clone(v)); | ||
| } else if (src instanceof Object) { | ||
| // Object | ||
| copy = {}; | ||
| seen.set(src, copy); | ||
| for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen); | ||
| } else { | ||
| // Unrecognized thing. It's better to throw here than to return `src`, as | ||
| // we don't know whether src needs to be deep-copied here. | ||
| throw Error(`Unable to clone ${src}`); | ||
| } | ||
| // Date | ||
| if (src instanceof Date) { | ||
| return new Date(src.getTime()) | ||
| } | ||
| // RegExp | ||
| if (src instanceof RegExp) { | ||
| return new RegExp(src) | ||
| } | ||
| // Arrays | ||
| if (Array.isArray(src)) { | ||
| return src.map(clone) | ||
| } | ||
| // ES6 Maps | ||
| if (map && src instanceof map) { | ||
| return new Map(Array.from(src.entries())) | ||
| } | ||
| // ES6 Sets | ||
| if (set && src instanceof set) { | ||
| return new Set(Array.from(src.values())) | ||
| } | ||
| // Object | ||
| if (src instanceof Object) { | ||
| circulars.push(src) | ||
| var obj = Object.create(src) | ||
| clones.push(obj) | ||
| for (var key in src) { | ||
| var idx = circulars.findIndex(function (i) { | ||
| return i === src[key] | ||
| }) | ||
| obj[key] = idx > -1 ? clones[idx] : baseClone(src[key], circulars, clones) | ||
| } | ||
| return obj | ||
| } | ||
| // ??? | ||
| return src | ||
| return copy | ||
| } | ||
| export default function clone (src) { | ||
| return baseClone(src, [], []) | ||
| export default function(src) { | ||
| return clone(src, new Map()) | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7110
16.14%1
-50%11
10%122
-7.58%1
Infinity%