Sha256: 9d6fc012e7e713f92edc40d3f0a3b514e54f7d4a903ea5217d9600d1b656eafe

Contents?: true

Size: 971 Bytes

Versions: 44

Compression:

Stored size: 971 Bytes

Contents

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

'use strict';

const hasOwn =
  Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);

/**
 * Checks whether needle is a strict subset of haystack.
 *
 * @param {*} haystack Value to test.
 * @param {*} needle Test function or value to look for in `haystack`.
 * @return {bool}
 */
function matchNode(haystack, needle) {
  if (typeof needle === 'function') {
    return needle(haystack);
  }
  if (isNode(needle) && isNode(haystack)) {
    return Object.keys(needle).every(function(property) {
      return (
        hasOwn(haystack, property) &&
        matchNode(haystack[property], needle[property])
      );
    });
  }
  return haystack === needle;
}

function isNode(value) {
  return typeof value === 'object' && value;
}

module.exports = matchNode;

Version data entries

44 entries across 15 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.52 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.52 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.51 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.51 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.51 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.50 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.50 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.50 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.49 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.49 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.49 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.48 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.48 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.48 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.47 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.47 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.47 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.46 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.46 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.46 node_modules/jscodeshift/dist/src/matchNode.js