X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=ae27035ff079c028f30bee9884d5b2de5521c18a;hb=f0bede86574750d1d894d16a86ef63f83948e7a0;hp=2472bf617621b87ef3752cc6000447918aa25300;hpb=4ccf551d961ef001acef6fafe1165ad9b6dac4e3;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 2472bf61..ae27035f 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -240,7 +240,7 @@ const deepClone = ( return clone as O } if (value instanceof Date) { - return new Date(value.valueOf()) as O + return new Date(value.getTime()) as O } if (typeof value !== 'object' || value === null) { return value as unknown as O @@ -261,6 +261,17 @@ export const clone = (object: T): T => { return deepClone(object as CloneableData) as T } +/** + * Detects whether the given value is an asynchronous function or not. + * + * @param fn - Unknown value. + * @returns `true` if `fn` was an asynchronous function, otherwise `false`. + * @internal + */ +export const isAsyncFunction = (fn: unknown): fn is (...args: unknown[]) => Promise => { + return typeof fn === 'function' && fn.constructor.name === 'AsyncFunction' +} + export const isObject = (value: unknown): value is object => { return value != null && typeof value === 'object' && !Array.isArray(value) }