(a, b)
| 73 | |
| 74 | /** @param {any} a @param {import('./types.d.ts').ObjectShape} b */ |
| 75 | export function matchObjectShape(a, b) { |
| 76 | if (typeof a !== "object" || typeof b !== "object") { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | const aKeys = Object.keys(a).sort(); |
| 81 | const bKeys = Object.keys(b).sort(); |
| 82 | if (aKeys.toString() !== bKeys.toString()) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | for (const key of aKeys) { |
| 87 | if (a[key] === undefined || b[key] === undefined) { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | if (b[key] === Function && typeof a[key] === "function") { |
| 92 | continue; |
| 93 | } |
| 94 | if (b[key] === Object && typeof a[key] === "object") { |
| 95 | continue; |
| 96 | } |
| 97 | if (b[key] === Number && typeof a[key] === "number") { |
| 98 | continue; |
| 99 | } |
| 100 | if (b[key] === String && typeof a[key] === "string") { |
| 101 | continue; |
| 102 | } |
| 103 | if (b[key] === Boolean && typeof a[key] === "boolean") { |
| 104 | continue; |
| 105 | } |
| 106 | if (b[key] === WebAssembly.Memory && a[key] instanceof WebAssembly.Memory) { |
| 107 | continue; |
| 108 | } |
| 109 | // @ts-ignore |
| 110 | if (typeof a[key] === "object" && matchObjectShape(a[key], b[key])) { |
| 111 | continue; |
| 112 | } |
| 113 | |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | /** @param {() => any} fn */ |
| 121 | export function throws(fn) { |
no outgoing calls
no test coverage detected