fix: isEqual

This commit is contained in:
Tristan Yang
2022-06-23 15:55:59 +08:00
parent 0f7072cc8c
commit 0310d764ac
3 changed files with 3 additions and 21 deletions
-19
View File
@@ -11,25 +11,6 @@ export const isImage = (file_type = "", size = 0) => {
return file_type.startsWith("image") && size <= FILE_IMAGE_SIZE;
};
const deepSortObject = (obj) => {
return Object.fromEntries(
Object.entries(obj)
.map((entry) => [
entry[0],
typeof entry[1] === "object" ? deepSortObject(entry[1]) : entry[1]
])
.sort()
);
};
export const isObjectEqual = (obj1, obj2) => {
// Check for reference equal
if (obj1 === obj2) return true;
// Check for deep equal
let o1 = JSON.stringify(deepSortObject(obj1 ?? {}));
let o2 = JSON.stringify(deepSortObject(obj2 ?? {}));
return o1 === o2;
};
export const isTreatAsImage = (file) => {
let isImage = false;
if (!file) return isImage;