From: Jérôme Benoit Date: Tue, 13 Feb 2024 23:42:26 +0000 (+0100) Subject: refactor: use native cloning function X-Git-Tag: v1.2.37~61 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3fad0dec3efcbef64a3a417d8a7c8aef508afd5d;p=e-mobility-charging-stations-simulator.git refactor: use native cloning function Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 9bd5a9bb..12c206ff 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -12,7 +12,6 @@ import { minutesToSeconds, secondsToMilliseconds } from 'date-fns' -import { clone as cloneDeep } from 'rambda' import { Constants } from './Constants.js' import { @@ -213,7 +212,7 @@ export const extractTimeSeriesValues = (timeSeries: TimestampedData[]): number[] } export const clone = (object: T): T => { - return cloneDeep(object) + return structuredClone(object) } /** diff --git a/tests/utils/Utils.test.ts b/tests/utils/Utils.test.ts index 7bee08ac..3b2a52ae 100644 --- a/tests/utils/Utils.test.ts +++ b/tests/utils/Utils.test.ts @@ -341,14 +341,17 @@ await describe('Utils test suite', async () => { const date = new Date() expect(clone(date)).toStrictEqual(date) expect(clone(date) === date).toBe(false) + // The URL object seems to have not enumerable properties + const url = new URL('https://domain.tld') + expect(clone(url)).toStrictEqual({}) const map = new Map([['1', '2']]) - expect(clone(map)).toStrictEqual({}) + expect(clone(map)).toStrictEqual(map) const set = new Set(['1']) - expect(clone(set)).toStrictEqual({}) + expect(clone(set)).toStrictEqual(set) const weakMap = new WeakMap([[{ 1: 1 }, { 2: 2 }]]) - expect(clone(weakMap)).toStrictEqual({}) + expect(() => clone(weakMap)).toThrow(new Error('# could not be cloned.')) const weakSet = new WeakSet([{ 1: 1 }, { 2: 2 }]) - expect(clone(weakSet)).toStrictEqual({}) + expect(() => clone(weakSet)).toThrow(new Error('# could not be cloned.')) }) await it('Verify hasOwnProp()', () => {