diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-03-19 20:32:15 +0900 |
|---|---|---|
| committer | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-03-19 20:32:15 +0900 |
| commit | 4ab9f663569b5e5bf1ad4367aebd4074e4b35e94 (patch) | |
| tree | 31f9ac5f6a3b961aa5c779738b93bafb8ec4fe47 | |
| parent | chore(storybook): fix storybook build (#15678) (diff) | |
| download | misskey-4ab9f663569b5e5bf1ad4367aebd4074e4b35e94.tar.gz misskey-4ab9f663569b5e5bf1ad4367aebd4074e4b35e94.tar.bz2 misskey-4ab9f663569b5e5bf1ad4367aebd4074e4b35e94.zip | |
Update deep-equal.ts
| -rw-r--r-- | packages/frontend/src/utility/deep-equal.ts | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/packages/frontend/src/utility/deep-equal.ts b/packages/frontend/src/utility/deep-equal.ts index c64d82c6cc..2859641dc7 100644 --- a/packages/frontend/src/utility/deep-equal.ts +++ b/packages/frontend/src/utility/deep-equal.ts @@ -3,24 +3,35 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -export function deepEqual(a: any, b: any): boolean { +type JsonLike = string | number | boolean | null | undefined | JsonLike[] | { [key: string]: JsonLike } | Map<string, JsonLike>; + +export function deepEqual(a: JsonLike, b: JsonLike): boolean { if (a === b) return true; + if (typeof a !== typeof b) return false; if (a === null) return b === null; + if (a === undefined) return b === undefined; + if (Array.isArray(a) && Array.isArray(b)) { if (a.length !== b.length) return false; for (let i = 0; i < a.length; i++) { if (!deepEqual(a[i], b[i])) return false; } return true; + } else if (a instanceof Map && b instanceof Map) { + if (a.size !== b.size) return false; + for (const [k, v] of a) { + if (!deepEqual(v, b.get(k))) return false; + } + return true; } else if (((typeof a) === 'object') && ((typeof b) === 'object')) { const aks = Object.keys(a); - const bks = Object.keys(b); + const bks = Object.keys(b as { [key: string]: JsonLike }); if (aks.length !== bks.length) return false; for (let i = 0; i < aks.length; i++) { const k = aks[i]; - if (!deepEqual(a[k], b[k])) return false; + if (!deepEqual(a[k], (b as { [key: string]: JsonLike })[k])) return false; } return true; } |