UNPKG

react-shallow-query

Version:

A React utility that makes querying a shallow rendered component easier.

50 lines (39 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function displayName(_ref, fragment) { var type = _ref.type; var displayName = type.displayName; var name = type.name; if ((displayName || name) === fragment) return true; // This is a fix for browsers that don't support Function.name (Internet Explorer). if (typeof name === "undefined") { var funcString = type.toString(); var match = funcString.match(/function\s([^(]{1,})\(/); return match && match[1] === fragment; } return false; } function className(object, fragment) { var className = object.props.className; // Remove the period. fragment = fragment.slice(1); // Search in the className for the fragment. return className && className.split(" ").some(function (name) { return name == fragment; }); } function type(object, fragment) { return object.type === fragment; } function id(object, fragment) { return object.props.id == fragment.slice(1); } exports["default"] = { displayName: displayName, className: className, type: type, id: id }; module.exports = exports["default"];