|
1 | 1 | import { isEqual, mapValues, union } from 'lodash' |
2 | 2 |
|
3 | | -import type { JSONValue } from '../types/json' |
4 | | - |
5 | 3 | export const removeUndefinedProps = <T extends object>(obj: T): T => { |
6 | 4 | const newObj: any = {} |
7 | 5 |
|
@@ -132,60 +130,6 @@ export function errorToObject(value: any) { |
132 | 130 | return value |
133 | 131 | } |
134 | 132 |
|
135 | | -export function hasKey<T extends object, K extends PropertyKey>( |
136 | | - obj: T | undefined | null | string | number | boolean, |
137 | | - key: K, |
138 | | -): obj is T & Record<K, unknown> { |
139 | | - return obj != null && typeof obj === 'object' && key in obj |
140 | | -} |
141 | | - |
142 | 133 | export function deepCopy<T>(obj: T): T { |
143 | 134 | return JSON.parse(JSON.stringify(obj)) as T |
144 | 135 | } |
145 | | - |
146 | | -export function deepEqual( |
147 | | - a: JSONValue | undefined, |
148 | | - b: JSONValue | undefined, |
149 | | -): boolean { |
150 | | - if (a === b) return true |
151 | | - |
152 | | - if ( |
153 | | - typeof a === 'string' || |
154 | | - typeof b === 'string' || |
155 | | - typeof a === 'boolean' || |
156 | | - typeof b === 'boolean' || |
157 | | - typeof a === 'number' || |
158 | | - typeof b === 'number' || |
159 | | - a === null || |
160 | | - b === null || |
161 | | - a === undefined || |
162 | | - b === undefined |
163 | | - ) { |
164 | | - return false |
165 | | - } |
166 | | - |
167 | | - if (Array.isArray(a) || Array.isArray(b)) { |
168 | | - if (!Array.isArray(a)) return false |
169 | | - if (!Array.isArray(b)) return false |
170 | | - |
171 | | - if (a.length !== b.length) return false |
172 | | - |
173 | | - for (let i = 0; i < a.length; i++) { |
174 | | - if (!deepEqual(a[i], b[i])) return false |
175 | | - } |
176 | | - |
177 | | - return true |
178 | | - } |
179 | | - |
180 | | - const keysA = Object.keys(a) |
181 | | - const keysB = Object.keys(b) |
182 | | - |
183 | | - if (keysA.length !== keysB.length) return false |
184 | | - |
185 | | - for (const key of keysA) { |
186 | | - if (!keysB.includes(key)) return false |
187 | | - if (!deepEqual(a[key], b[key])) return false |
188 | | - } |
189 | | - |
190 | | - return true |
191 | | -} |
0 commit comments