From e16ab80c7cf3ffec63201cb0b91c6616367598a6 Mon Sep 17 00:00:00 2001 From: trevor-anderson Date: Tue, 20 Feb 2024 10:07:30 -0500 Subject: [PATCH] fix: rm extraneous deepCopy util --- src/utils/deepCopy.ts | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 src/utils/deepCopy.ts diff --git a/src/utils/deepCopy.ts b/src/utils/deepCopy.ts deleted file mode 100644 index 0bfa8ed3..00000000 --- a/src/utils/deepCopy.ts +++ /dev/null @@ -1,42 +0,0 @@ -import type { Primitive } from "type-fest"; - -/** - * This function creates a same-type deep copy of the input without using methods - * like `JSON.parse(JSON.stringify(input))` which can't handle certain types of - * data like `undefined`, `null`, `Date`, `Map`s, etc. - * - * > Note: The `structuredClone` Web API method is a better alternative to this - * implementation, but as of May 2023, it's only supported in the very latest - * versions of some browsers like Chrome and Safari, _and_ the Nodejs version - * used in the dev-env would have to be bumped to at least v17 as well. Until - * these compatibility issues are resolved, use this function instead. - */ -export const deepCopy = (input: T): T => { - return typeof input === "bigint" || - typeof input === "boolean" || - typeof input === "number" || - typeof input === "string" || - typeof input === "symbol" || - typeof input === "undefined" || - input === null - ? input // else typeof input is "object" - : input instanceof Date - ? (new Date(input.getTime()) as T) - : input instanceof Map - ? (new Map(Array.from(input).map(([key, value]) => [deepCopy(key), deepCopy(value)])) as T) - : input instanceof Set - ? (new Set(Array.from(input).map((item) => deepCopy(item))) as T) - : Array.isArray(input) - ? (input.map((item) => deepCopy(item)) as T) - : (Object.fromEntries( - Object.entries(input).map(([key, value]) => [key, deepCopy(value)]) - ) as T); -}; - -export type DeepCopyInput = - | Primitive - | Date - | Map - | Set - | Array - | Record;