From f522d7b906f8a45a7e4fd349abe3f83bf8fc3d69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 28 Jul 2023 15:12:04 +0200 Subject: [PATCH] switch to ESM MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- busy-wait.js => busy-wait.mjs | 4 +-- deep-clone-object.js => deep-clone-object.mjs | 12 ++++++--- empty-array.js => empty-array.mjs | 4 +-- fibonacci.js => fibonacci.mjs | 2 +- is-empty-object.js => is-empty-object.mjs | 4 +-- is-undefined.js => is-undefined.mjs | 2 +- max.js => max.mjs | 4 +-- package.json | 25 ++++++++++--------- pnpm-lock.yaml | 7 ++++++ promise-handling.js => promise-handling.mjs | 2 +- quick-select.js => quick-select.mjs | 4 +-- random.js => random.mjs | 8 +++--- ...lone-object.js => shallow-clone-object.mjs | 6 ++--- uuid-generator.js => uuid-generator.mjs | 6 ++--- 14 files changed, 51 insertions(+), 39 deletions(-) rename busy-wait.js => busy-wait.mjs (96%) rename deep-clone-object.js => deep-clone-object.mjs (77%) rename empty-array.js => empty-array.mjs (89%) rename fibonacci.js => fibonacci.mjs (97%) rename is-empty-object.js => is-empty-object.mjs (91%) rename is-undefined.js => is-undefined.mjs (94%) rename max.js => max.mjs (92%) rename promise-handling.js => promise-handling.mjs (96%) rename quick-select.js => quick-select.mjs (98%) rename random.js => random.mjs (95%) rename shallow-clone-object.js => shallow-clone-object.mjs (86%) rename uuid-generator.js => uuid-generator.mjs (83%) diff --git a/busy-wait.js b/busy-wait.mjs similarity index 96% rename from busy-wait.js rename to busy-wait.mjs index a851a30..a785a7e 100644 --- a/busy-wait.js +++ b/busy-wait.mjs @@ -1,5 +1,5 @@ -const Benchmark = require('benny') -const { sleep } = require('./benchmark-utils') +import Benchmark from 'benny' +import { sleep } from './benchmark-utils.js' const timeout = 2000 const interval = 1000 diff --git a/deep-clone-object.js b/deep-clone-object.mjs similarity index 77% rename from deep-clone-object.js rename to deep-clone-object.mjs index 0f480c4..52a1bac 100644 --- a/deep-clone-object.js +++ b/deep-clone-object.mjs @@ -1,8 +1,9 @@ /* eslint-disable no-unused-vars */ -const Benchmark = require('benny') -const _ = require('lodash') -const clone = require('just-clone') -const { generateRandomObject } = require('./benchmark-utils') +import Benchmark from 'benny' +import _ from 'lodash' +import clone from 'just-clone' +import deepClone from 'deep-clone' +import { generateRandomObject } from './benchmark-utils.js' const object = generateRandomObject() @@ -20,6 +21,9 @@ Benchmark.suite( Benchmark.add('just-clone', (obj = object) => { const objClone = clone(obj) }), + Benchmark.add('deep-clone', (obj = object) => { + const objClone = deepClone(obj) + }), Benchmark.cycle(), Benchmark.complete(), Benchmark.save({ diff --git a/empty-array.js b/empty-array.mjs similarity index 89% rename from empty-array.js rename to empty-array.mjs index c900a42..887e0ce 100644 --- a/empty-array.js +++ b/empty-array.mjs @@ -1,5 +1,5 @@ -const Benchmark = require('benny') -const { generateRandomNumberArray } = require('./benchmark-utils') +import Benchmark from 'benny' +import { generateRandomNumberArray } from './benchmark-utils.js' const size = 10000 let testArray = generateRandomNumberArray(size) diff --git a/fibonacci.js b/fibonacci.mjs similarity index 97% rename from fibonacci.js rename to fibonacci.mjs index a62f471..00130ce 100644 --- a/fibonacci.js +++ b/fibonacci.mjs @@ -1,4 +1,4 @@ -const Benchmark = require('benny') +import Benchmark from 'benny' const number = 30 diff --git a/is-empty-object.js b/is-empty-object.mjs similarity index 91% rename from is-empty-object.js rename to is-empty-object.mjs index 02c3a29..17072a9 100644 --- a/is-empty-object.js +++ b/is-empty-object.mjs @@ -1,5 +1,5 @@ -const Benchmark = require('benny') -const { generateRandomObject } = require('./benchmark-utils') +import Benchmark from 'benny' +import { generateRandomObject } from './benchmark-utils.js' const object = generateRandomObject() diff --git a/is-undefined.js b/is-undefined.mjs similarity index 94% rename from is-undefined.js rename to is-undefined.mjs index 549171e..a04113b 100644 --- a/is-undefined.js +++ b/is-undefined.mjs @@ -1,4 +1,4 @@ -const Benchmark = require('benny') +import Benchmark from 'benny' Benchmark.suite( 'Is undefined', diff --git a/max.js b/max.mjs similarity index 92% rename from max.js rename to max.mjs index 5a48647..de7602e 100644 --- a/max.js +++ b/max.mjs @@ -1,5 +1,5 @@ -const Benchmark = require('benny') -const { generateRandomNumberArray } = require('./benchmark-utils') +import Benchmark from 'benny' +import { generateRandomNumberArray } from './benchmark-utils.js' const size = 10000 const testArray = generateRandomNumberArray(size) diff --git a/package.json b/package.json index c845cd4..2573d22 100644 --- a/package.json +++ b/package.json @@ -32,18 +32,18 @@ "scripts": { "preinstall": "npx --yes only-allow pnpm", "prepare": "node prepare.js", - "benchmark:busy-wait": "node busy-wait.js", - "benchmark:empty-array": "node empty-array.js", - "benchmark:deep-clone-object": "node deep-clone-object.js", - "benchmark:shallow-clone-object": "node shallow-clone-object.js", - "benchmark:is-empty-object": "node is-empty-object.js", - "benchmark:is-undefined": "node is-undefined.js", - "benchmark:quick-select": "node quick-select.js", - "benchmark:max": "node max.js", - "benchmark:promise-handling": "node promise-handling.js", - "benchmark:fibonacci": "node fibonacci.js", - "benchmark:random": "node random.js", - "benchmark:uuid-generator": "node uuid-generator.js", + "benchmark:busy-wait": "node busy-wait.mjs", + "benchmark:empty-array": "node empty-array.mjs", + "benchmark:deep-clone-object": "node deep-clone-object.mjs", + "benchmark:shallow-clone-object": "node shallow-clone-object.mjs", + "benchmark:is-empty-object": "node is-empty-object.mjs", + "benchmark:is-undefined": "node is-undefined.mjs", + "benchmark:quick-select": "node quick-select.mjs", + "benchmark:max": "node max.mjs", + "benchmark:promise-handling": "node promise-handling.mjs", + "benchmark:fibonacci": "node fibonacci.mjs", + "benchmark:random": "node random.mjs", + "benchmark:uuid-generator": "node uuid-generator.mjs", "format": "prettier . --cache --write; standard . --fix", "lint": "eslint . --cache", "lint:fix": "eslint . --cache --fix", @@ -53,6 +53,7 @@ "license": "MIT", "dependencies": { "benny": "^3.7.1", + "deep-clone": "^4.0.0", "just-clone": "^6.2.0", "lodash": "^4.17.21", "microtime": "^3.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 530e1c1..e50c2b0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ dependencies: benny: specifier: ^3.7.1 version: 3.7.1 + deep-clone: + specifier: ^4.0.0 + version: 4.0.0 just-clone: specifier: ^6.2.0 version: 6.2.0 @@ -507,6 +510,10 @@ packages: ms: 2.1.2 dev: true + /deep-clone@4.0.0: + resolution: {integrity: sha512-bMvDVR8GiGCGHT4SgqXyXDD9Zmo3kv9YLq8aSO2xslP97A3mFkpNBg+t+fjXERvewzhmtk9efvL+V52iVkD0lg==} + dev: false + /deep-is@0.1.4: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} dev: true diff --git a/promise-handling.js b/promise-handling.mjs similarity index 96% rename from promise-handling.js rename to promise-handling.mjs index 11e0a96..b3b0210 100644 --- a/promise-handling.js +++ b/promise-handling.mjs @@ -1,4 +1,4 @@ -const Benchmark = require('benny') +import Benchmark from 'benny' /** * diff --git a/quick-select.js b/quick-select.mjs similarity index 98% rename from quick-select.js rename to quick-select.mjs index 7a2486a..34ba13d 100644 --- a/quick-select.js +++ b/quick-select.mjs @@ -1,5 +1,5 @@ -const Benchmark = require('benny') -const { generateRandomInteger } = require('./benchmark-utils') +import Benchmark from 'benny' +import { generateRandomInteger } from './benchmark-utils.js' /** * @param numberOfWorkers diff --git a/random.js b/random.mjs similarity index 95% rename from random.js rename to random.mjs index 8c0fa86..f814d3d 100644 --- a/random.js +++ b/random.mjs @@ -1,9 +1,9 @@ -const crypto = require('crypto') -const Benchmark = require('benny') -const { +import crypto from 'crypto' +import Benchmark from 'benny' +import { secureRandom, secureRandomWithRandomValues -} = require('./benchmark-utils') +} from './benchmark-utils.js' const maximum = 281474976710654 diff --git a/shallow-clone-object.js b/shallow-clone-object.mjs similarity index 86% rename from shallow-clone-object.js rename to shallow-clone-object.mjs index f8e193b..05a97ec 100644 --- a/shallow-clone-object.js +++ b/shallow-clone-object.mjs @@ -1,7 +1,7 @@ /* eslint-disable no-unused-vars */ -const Benchmark = require('benny') -const _ = require('lodash') -const { generateRandomObject } = require('./benchmark-utils') +import Benchmark from 'benny' +import _ from 'lodash' +import { generateRandomObject } from './benchmark-utils.js' const object = generateRandomObject() diff --git a/uuid-generator.js b/uuid-generator.mjs similarity index 83% rename from uuid-generator.js rename to uuid-generator.mjs index 08641c1..92e15d8 100644 --- a/uuid-generator.js +++ b/uuid-generator.mjs @@ -1,6 +1,6 @@ -const crypto = require('crypto') -const Benchmark = require('benny') -const { v4: uuid } = require('uuid') +import crypto from 'crypto' +import Benchmark from 'benny' +import { v4 as uuid } from 'uuid' Benchmark.suite( 'UUIDv4 generator', -- 2.34.1