MCPcopy
hub / github.com/posthtml/posthtml / compare

Function compare

lib/api.js:117–145  ·  view source on GitHub ↗

@private

(expected, actual)

Source from the content-addressed store, hash-verified

115
116/** @private */
117function compare (expected, actual) {
118 if (expected instanceof RegExp) {
119 if (typeof actual === 'object') return false
120 if (typeof actual === 'string') return expected.test(actual)
121 }
122
123 if (typeof expected !== typeof actual) return false
124 if (typeof expected !== 'object' || expected === null) {
125 return expected === actual
126 }
127
128 if (Array.isArray(expected)) {
129 return expected.every(exp => [].some.call(actual, act => compare(exp, act)))
130 }
131
132 return Object.keys(expected).every(key => {
133 const ao = actual[key]
134 const eo = expected[key]
135
136 if (typeof eo === 'object' && eo !== null && ao !== null) {
137 return compare(eo, ao)
138 }
139 if (typeof eo === 'boolean') {
140 return eo !== (ao == null)
141 }
142
143 return ao === eo
144 })
145}

Callers 1

matchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…