From 8a4f882a2486682b72195ad978ec1d81604b452b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 21 Mar 2024 20:24:03 +0100 Subject: [PATCH] refactor: use ramdba helper for builtin types MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/performance/PerformanceStatistics.ts | 4 ++-- src/utils/Utils.ts | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) 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 -- 2.34.1