How to use object-is - 5 common examples

To help you get started, we’ve selected a few object-is examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airbnb / enzyme / packages / enzyme / src / selectors.js View on Github external
return has(nodeProps, token.name);
  }
  // Only the exact value operator ("=") can match non-strings
  if (typeof nodePropValue !== 'string' || typeof value !== 'string') {
    if (operator !== EXACT_ATTRIBUTE_OPERATOR) {
      return false;
    }
  }
  switch (operator) {
    /**
     * Represents an element with the att attribute whose value is exactly "val".
     * @example
     * [attr="val"] matches attr="val"
     */
    case EXACT_ATTRIBUTE_OPERATOR:
      return is(nodePropValue, value);
    /**
     * Represents an element with the att attribute whose value is a whitespace-separated
     * list of words, one of which is exactly
     * @example
     *  [rel~="copyright"] matches rel="copyright other"
     */
    case WHITELIST_ATTRIBUTE_OPERATOR:
      return nodePropValue.split(' ').indexOf(value) !== -1;
    /**
     * Represents an element with the att attribute, its value either being exactly the
     * value or beginning with the value immediately followed by "-"
     * @example
     * [hreflang|="en"] matches hreflang="en-US"
     */
    case HYPHENATED_ATTRIBUTE_OPERATOR:
      return nodePropValue === value || nodePropValue.startsWith(`${value}-`);
github FormidableLabs / react-ssr-prepass / src / internals / dispatcher.js View on Github external
function areHookInputsEqual(
  nextDeps: Array,
  prevDeps: Array | null
) {
  // NOTE: The warnings that are used in ReactPartialRendererHooks are obsolete
  // in a prepass, since these issues will be caught by a subsequent renderer anyway
  if (prevDeps === null) {
    return false
  }

  for (let i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
    if (!is(nextDeps[i], prevDeps[i])) {
      return false
    }
  }

  return true
}
github airbnb / prop-types / src / nonNegativeNumber.js View on Github external
function isNonNegative(x) {
  return typeof x === 'number' && isFinite(x) && x >= 0 && !is(x, -0);
}
github airbnb / prop-types / src / requiredBy.js View on Github external
requiredBy.isRequired = function requiredByRequired(props, propName, componentName, ...rest) {
    const { [propName]: propValue } = props;
    if (is(propValue, defaultValue)) {
      return new TypeError(`${componentName}: prop “${propName}” must be present.`);
    }
    return propType.isRequired(props, propName, componentName, ...rest);
  };
github airbnb / prop-types / src / requiredBy.js View on Github external
function requiredBy(props, propName, componentName, ...rest) {
    if (props[requiredByPropName]) {
      const { [propName]: propValue } = props;
      if (is(propValue, defaultValue) || typeof propValue === 'undefined') {
        return new TypeError(
          `${componentName}: when ${requiredByPropName} is true, prop “${propName}” must be present.`,
        );
      }
    }
    return propType(props, propName, componentName, ...rest);
  }
  requiredBy.isRequired = function requiredByRequired(props, propName, componentName, ...rest) {

object-is

ES2015-compliant shim for Object.is - differentiates between -0 and +0

MIT
Latest version published 5 days ago

Package Health Score

74 / 100
Full package analysis

Popular object-is functions