1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | const hasOwn =
|
12 | Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function matchNode(haystack, needle) {
|
22 | if (typeof needle === 'function') {
|
23 | return needle(haystack);
|
24 | }
|
25 | if (isNode(needle) && isNode(haystack)) {
|
26 | return Object.keys(needle).every(function(property) {
|
27 | return (
|
28 | hasOwn(haystack, property) &&
|
29 | matchNode(haystack[property], needle[property])
|
30 | );
|
31 | });
|
32 | }
|
33 | return haystack === needle;
|
34 | }
|
35 |
|
36 | function isNode(value) {
|
37 | return typeof value === 'object' && value;
|
38 | }
|
39 |
|
40 | module.exports = matchNode;
|