array-comparisoncomparisoncomparison-tooldeep-diffdiffjson-diffnodejsobject-comparisonobject-diffobjectdiffobjectdifferencereactstreamingstreaming-datatypescript
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
757 B
28 lines
757 B
import { Options } from "./model"; |
|
|
|
export function isEqual( |
|
a: any, |
|
b: any, |
|
options: Options = { discardArrayOrder: false } |
|
): boolean { |
|
if (typeof a !== typeof b) return false; |
|
if (Array.isArray(a)) { |
|
if (a.length !== b.length) { |
|
return false; |
|
} |
|
if (options.discardArrayOrder) { |
|
return a.every((v) => |
|
b.some((nextV: any) => JSON.stringify(nextV) === JSON.stringify(v)) |
|
); |
|
} |
|
return a.every((v, i) => JSON.stringify(v) === JSON.stringify(b[i])); |
|
} |
|
if (typeof a === "object") { |
|
return JSON.stringify(a) === JSON.stringify(b); |
|
} |
|
return a === b; |
|
} |
|
|
|
export function isObject(value: any): value is Record<string, any> { |
|
return !!value && typeof value === "object" && !Array.isArray(value); |
|
}
|
|
|