From: Jérôme Benoit Date: Thu, 21 Mar 2024 19:24:03 +0000 (+0100) Subject: refactor: use ramdba helper for builtin types X-Git-Tag: v1.3.1~17 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;ds=sidebyside;h=8a4f882a2486682b72195ad978ec1d81604b452b;p=e-mobility-charging-stations-simulator.git refactor: use ramdba helper for builtin types Signed-off-by: Jérôme Benoit --- diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 6363be1c..265cb6c9 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -5,7 +5,7 @@ import type { URL } from 'node:url' import { parentPort } from 'node:worker_threads' import { secondsToMilliseconds } from 'date-fns' -import { mean, median } from 'rambda' +import { is, mean, median } from 'rambda' import { BaseError } from '../exception/index.js' import { @@ -107,7 +107,7 @@ export class PerformanceStatistics { try { performance.measure(name, markId) } catch (error) { - if (error instanceof Error && error.message.includes('performance mark has not been set')) { + if (is(Error, error) && error.message.includes('performance mark has not been set')) { /* Ignore */ } else { throw error diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 7ff24ac8..aeed9b0f 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -12,6 +12,7 @@ import { minutesToSeconds, secondsToMilliseconds } from 'date-fns' +import { is } from 'rambda' import { type JsonType, @@ -215,11 +216,11 @@ export const clone = (object: T): T => { * @internal */ export const isAsyncFunction = (fn: unknown): fn is (...args: unknown[]) => Promise => { - return typeof fn === 'function' && fn.constructor.name === 'AsyncFunction' + return is(Function, fn) && fn.constructor.name === 'AsyncFunction' } export const isObject = (value: unknown): value is object => { - return value != null && typeof value === 'object' && !Array.isArray(value) + return value != null && !Array.isArray(value) && is(Object, value) } export const hasOwnProp = (value: unknown, property: PropertyKey): boolean => { @@ -277,7 +278,7 @@ export const JSONStringify = < return JSON.stringify( object, (_, value: Record) => { - if (value instanceof Map) { + if (is(Map, value)) { switch (mapFormat) { case MapStringifyFormat.object: return { ...Object.fromEntries>>(value.entries()) } @@ -285,7 +286,7 @@ export const JSONStringify = < default: return [...value] } - } else if (value instanceof Set) { + } else if (is(Set, value)) { return [...value] as JsonType[] } return value