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.45 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.45 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.45 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.44 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.44 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.44 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.43 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.43 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.43 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.42 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.42 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.42 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.41 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.41 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.41 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.40 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.40 node_modules/jscodeshift/src/matchNode.js
immosquare-cleaner-0.1.40 node_modules/jscodeshift/dist/matchNode.js
immosquare-cleaner-0.1.39 node_modules/jscodeshift/dist/src/matchNode.js
immosquare-cleaner-0.1.39 node_modules/jscodeshift/src/matchNode.js