MCPcopy
hub / github.com/vuejs/core / looseEqual

Function looseEqual

packages/shared/src/looseEqual.ts:12–53  ·  view source on GitHub ↗
(a: any, b: any)

Source from the content-addressed store, hash-verified

10}
11
12export function looseEqual(a: any, b: any): boolean {
13 if (a === b) return true
14 let aValidType = isDate(a)
15 let bValidType = isDate(b)
16 if (aValidType || bValidType) {
17 return aValidType && bValidType ? a.getTime() === b.getTime() : false
18 }
19 aValidType = isSymbol(a)
20 bValidType = isSymbol(b)
21 if (aValidType || bValidType) {
22 return a === b
23 }
24 aValidType = isArray(a)
25 bValidType = isArray(b)
26 if (aValidType || bValidType) {
27 return aValidType && bValidType ? looseCompareArrays(a, b) : false
28 }
29 aValidType = isObject(a)
30 bValidType = isObject(b)
31 if (aValidType || bValidType) {
32 if (!aValidType || !bValidType) {
33 return false
34 }
35 const aKeysCount = Object.keys(a).length
36 const bKeysCount = Object.keys(b).length
37 if (aKeysCount !== bKeysCount) {
38 return false
39 }
40 for (const key in a) {
41 const aHasKey = a.hasOwnProperty(key)
42 const bHasKey = b.hasOwnProperty(key)
43 if (
44 (aHasKey && !bHasKey) ||
45 (!aHasKey && bHasKey) ||
46 !looseEqual(a[key], b[key])
47 ) {
48 return false
49 }
50 }
51 }
52 return String(a) === String(b)
53}
54
55export function looseIndexOf(arr: any[], val: any): number {
56 return arr.findIndex(item => looseEqual(item, val))

Callers 11

looseEqual.spec.tsFile · 0.90
ssrRenderDynamicModelFunction · 0.90
ssrGetDynamicModelPropsFunction · 0.90
setCheckedFunction · 0.90
createdFunction · 0.90
beforeUpdateFunction · 0.90
setSelectedFunction · 0.90
initVModelForSSRFunction · 0.90
hasPropValueChangedFunction · 0.90
looseCompareArraysFunction · 0.85
looseIndexOfFunction · 0.85

Calls 5

isDateFunction · 0.90
isSymbolFunction · 0.90
isObjectFunction · 0.90
looseCompareArraysFunction · 0.85
StringInterface · 0.85

Tested by

no test coverage detected