refactor: use ramdba helper for builtin types
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 21 Mar 2024 19:24:03 +0000 (20:24 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 21 Mar 2024 19:24:03 +0000 (20:24 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/performance/PerformanceStatistics.ts
src/utils/Utils.ts

index 6363be1c6b2196842b49dc1140ca9887d5b4b385..265cb6c963918b1a3970a95e5822742f3202c0d4 100644 (file)
@@ -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
index 7ff24ac8a423b7ece4ab779dd87c3972f9dcf2d4..aeed9b0fa44b4a073bff682583c95695cbb954ac 100644 (file)
@@ -12,6 +12,7 @@ import {
   minutesToSeconds,
   secondsToMilliseconds
 } from 'date-fns'
+import { is } from 'rambda'
 
 import {
   type JsonType,
@@ -215,11 +216,11 @@ export const clone = <T>(object: T): T => {
  * @internal
  */
 export const isAsyncFunction = (fn: unknown): fn is (...args: unknown[]) => Promise<unknown> => {
-  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<string, unknown>) => {
-      if (value instanceof Map) {
+      if (is(Map, value)) {
         switch (mapFormat) {
           case MapStringifyFormat.object:
             return { ...Object.fromEntries<Map<string, Record<string, unknown>>>(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