diff --git a/benchmark/index.js b/benchmark/index.js index 43ced8a..ecf99b5 100644 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -11,96 +11,96 @@ const plainObjectClone = require('plain-object-clone') const nanoCopy = require('nano-copy') const ramdaClone = require('ramda').clone const cloneDefaults = clone() -const cloneProto = clone({proto: true}) -const cloneCircles = clone({circles: true}) -const cloneCirclesProto = clone({circles: true, proto: true}) +const cloneProto = clone({ proto: true }) +const cloneCircles = clone({ circles: true }) +const cloneCirclesProto = clone({ circles: true, proto: true }) const max = 1000 -var run = bench([ +const run = bench([ function benchDeepCopy (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { deepCopy(obj) } setImmediate(cb) }, function benchLodashCloneDeep (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { lodashCloneDeep(obj) } setImmediate(cb) }, function benchCloneDeep (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneDeep(obj) } setImmediate(cb) }, function benchFastCopy (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { fastCopy(obj) } setImmediate(cb) }, function benchFastestJsonCopy (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { copyFastestJsonCopy(obj) } setImmediate(cb) }, function benchPlainObjectClone (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { plainObjectClone(obj) } setImmediate(cb) }, function benchNanoCopy (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { nanoCopy(obj) } setImmediate(cb) }, function benchRamdaClone (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { ramdaClone(obj) } setImmediate(cb) }, function benchJsonParseJsonStringify (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { JSON.parse(JSON.stringify(obj)) } setImmediate(cb) }, function benchRfdc (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneDefaults(obj) } setImmediate(cb) }, function benchRfdcProto (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneProto(obj) } setImmediate(cb) }, function benchRfdcCircles (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneCircles(obj) } setImmediate(cb) }, function benchRfdcCirclesProto (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneCirclesProto(obj) } setImmediate(cb) }, function benchStructuredClone (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { structuredClone(obj) } setImmediate(cb) - }, + } ], 100) run(run) diff --git a/benchmark/shallow.js b/benchmark/shallow.js index 7d5b802..0d70bcf 100644 --- a/benchmark/shallow.js +++ b/benchmark/shallow.js @@ -4,99 +4,99 @@ const deepCopy = require('deep-copy') const lodashCloneDeep = require('lodash.clonedeep') const cloneDeep = require('clone-deep') const fastCopy = require('fast-copy').default -const obj = {a: 'a', b: 'b', c: 'c'} +const obj = { a: 'a', b: 'b', c: 'c' } const clone = require('..') const copyFastestJsonCopy = require('fastest-json-copy').copy const plainObjectClone = require('plain-object-clone') const nanoCopy = require('nano-copy') const ramdaClone = require('ramda').clone const cloneDefaults = clone() -const cloneProto = clone({proto: true}) -const cloneCircles = clone({circles: true}) -const cloneCirclesProto = clone({circles: true, proto: true}) +const cloneProto = clone({ proto: true }) +const cloneCircles = clone({ circles: true }) +const cloneCirclesProto = clone({ circles: true, proto: true }) const max = 1000 /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^x$" }] */ -var run = bench([ +const run = bench([ function benchDeepCopy (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { deepCopy(obj) } setImmediate(cb) }, function benchLodashCloneDeep (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { lodashCloneDeep(obj) } setImmediate(cb) }, function benchCloneDeep (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneDeep(obj) } setImmediate(cb) }, function benchFastCopy (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { fastCopy(obj) } setImmediate(cb) }, function benchFastestJsonCopy (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { copyFastestJsonCopy(obj) } setImmediate(cb) }, function benchPlainObjectClone (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { plainObjectClone(obj) } setImmediate(cb) }, function benchNanoCopy (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { nanoCopy(obj) } setImmediate(cb) }, function benchRamdaClone (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { ramdaClone(obj) } setImmediate(cb) }, function benchObjectAssign (cb) { - for (var i = 0; i < max; i++) { - var x = Object.assign({}, obj) + for (let i = 0; i < max; i++) { + const x = Object.assign({}, obj) } setImmediate(cb) }, function benchObjectSpread (cb) { - for (var i = 0; i < max; i++) { - var x = {...obj} + for (let i = 0; i < max; i++) { + const x = { ...obj } } setImmediate(cb) }, function benchRfdc (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneDefaults(obj) } setImmediate(cb) }, function benchRfdcProto (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneProto(obj) } setImmediate(cb) }, function benchRfdcCircles (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneCircles(obj) } setImmediate(cb) }, function benchRfdcCirclesProto (cb) { - for (var i = 0; i < max; i++) { + for (let i = 0; i < max; i++) { cloneCirclesProto(obj) } setImmediate(cb) diff --git a/index.js b/index.js index 3b438a4..41a49c1 100644 --- a/index.js +++ b/index.js @@ -16,11 +16,11 @@ function rfdc (opts) { return opts.proto ? cloneProto : clone function cloneArray (a, fn) { - var keys = Object.keys(a) - var a2 = new Array(keys.length) - for (var i = 0; i < keys.length; i++) { - var k = keys[i] - var cur = a[k] + const keys = Object.keys(a) + const a2 = new Array(keys.length) + for (let i = 0; i < keys.length; i++) { + const k = keys[i] + const cur = a[k] if (typeof cur !== 'object' || cur === null) { a2[k] = cur } else if (cur instanceof Date) { @@ -40,10 +40,10 @@ function rfdc (opts) { if (Array.isArray(o)) return cloneArray(o, clone) if (o instanceof Map) return new Map(cloneArray(Array.from(o), clone)) if (o instanceof Set) return new Set(cloneArray(Array.from(o), clone)) - var o2 = {} - for (var k in o) { + const o2 = {} + for (const k in o) { if (Object.hasOwnProperty.call(o, k) === false) continue - var cur = o[k] + const cur = o[k] if (typeof cur !== 'object' || cur === null) { o2[k] = cur } else if (cur instanceof Date) { @@ -67,9 +67,9 @@ function rfdc (opts) { if (Array.isArray(o)) return cloneArray(o, cloneProto) if (o instanceof Map) return new Map(cloneArray(Array.from(o), cloneProto)) if (o instanceof Set) return new Set(cloneArray(Array.from(o), cloneProto)) - var o2 = {} - for (var k in o) { - var cur = o[k] + const o2 = {} + for (const k in o) { + const cur = o[k] if (typeof cur !== 'object' || cur === null) { o2[k] = cur } else if (cur instanceof Date) { @@ -89,17 +89,17 @@ function rfdc (opts) { } function rfdcCircles (opts) { - var refs = [] - var refsNew = [] + const refs = [] + const refsNew = [] return opts.proto ? cloneProto : clone function cloneArray (a, fn) { - var keys = Object.keys(a) - var a2 = new Array(keys.length) - for (var i = 0; i < keys.length; i++) { - var k = keys[i] - var cur = a[k] + const keys = Object.keys(a) + const a2 = new Array(keys.length) + for (let i = 0; i < keys.length; i++) { + const k = keys[i] + const cur = a[k] if (typeof cur !== 'object' || cur === null) { a2[k] = cur } else if (cur instanceof Date) { @@ -107,7 +107,7 @@ function rfdcCircles (opts) { } else if (ArrayBuffer.isView(cur)) { a2[k] = copyBuffer(cur) } else { - var index = refs.indexOf(cur) + const index = refs.indexOf(cur) if (index !== -1) { a2[k] = refsNew[index] } else { @@ -124,12 +124,12 @@ function rfdcCircles (opts) { if (Array.isArray(o)) return cloneArray(o, clone) if (o instanceof Map) return new Map(cloneArray(Array.from(o), clone)) if (o instanceof Set) return new Set(cloneArray(Array.from(o), clone)) - var o2 = {} + const o2 = {} refs.push(o) refsNew.push(o2) - for (var k in o) { + for (const k in o) { if (Object.hasOwnProperty.call(o, k) === false) continue - var cur = o[k] + const cur = o[k] if (typeof cur !== 'object' || cur === null) { o2[k] = cur } else if (cur instanceof Date) { @@ -141,7 +141,7 @@ function rfdcCircles (opts) { } else if (ArrayBuffer.isView(cur)) { o2[k] = copyBuffer(cur) } else { - var i = refs.indexOf(cur) + const i = refs.indexOf(cur) if (i !== -1) { o2[k] = refsNew[i] } else { @@ -160,11 +160,11 @@ function rfdcCircles (opts) { if (Array.isArray(o)) return cloneArray(o, cloneProto) if (o instanceof Map) return new Map(cloneArray(Array.from(o), cloneProto)) if (o instanceof Set) return new Set(cloneArray(Array.from(o), cloneProto)) - var o2 = {} + const o2 = {} refs.push(o) refsNew.push(o2) - for (var k in o) { - var cur = o[k] + for (const k in o) { + const cur = o[k] if (typeof cur !== 'object' || cur === null) { o2[k] = cur } else if (cur instanceof Date) { @@ -176,7 +176,7 @@ function rfdcCircles (opts) { } else if (ArrayBuffer.isView(cur)) { o2[k] = copyBuffer(cur) } else { - var i = refs.indexOf(cur) + const i = refs.indexOf(cur) if (i !== -1) { o2[k] = refsNew[i] } else { diff --git a/package.json b/package.json index d9edae1..1050e94 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "nano-copy": "^0.1.0", "plain-object-clone": "^1.1.0", "ramda": "^0.27.1", - "standard": "^11.0.1", + "standard": "^17.0.0", "tap": "^12.0.1", "tsd": "^0.7.4" }, diff --git a/test/index.js b/test/index.js index 458712f..a8e3cf4 100644 --- a/test/index.js +++ b/test/index.js @@ -223,7 +223,7 @@ function types (clone, label) { }) test(`${label} copies TypedArrays from object correctly`, async ({ ok, is, isNot }) => { const [input1, input2] = [rnd(10), rnd(10)] - var buffer = new ArrayBuffer(8) + const buffer = new ArrayBuffer(8) const int32View = new Int32Array(buffer) int32View[0] = input1 int32View[1] = input2 @@ -235,7 +235,7 @@ function types (clone, label) { }) test(`${label} copies TypedArrays from array correctly`, async ({ ok, is, isNot }) => { const [input1, input2] = [rnd(10), rnd(10)] - var buffer = new ArrayBuffer(16) + const buffer = new ArrayBuffer(16) const int32View = new Int32Array(buffer) int32View[0] = input1 int32View[1] = input2 @@ -247,7 +247,7 @@ function types (clone, label) { }) test(`${label} copies complex TypedArrays`, async ({ ok, deepEqual, is, isNot }) => { const [input1, input2, input3] = [rnd(10), rnd(10), rnd(10)] - var buffer = new ArrayBuffer(4) + const buffer = new ArrayBuffer(4) const view1 = new Int8Array(buffer, 0, 2) const view2 = new Int8Array(buffer, 2, 2) const view3 = new Int8Array(buffer)