is-equal-with.js 875 B

123456789101112131415161718192021222324252627282930313233
  1. var isFunction = require('./type/is-function');
  2. var isEqual = require('./is-equal');
  3. /**
  4. * @param {*} value The value to compare.
  5. * @param {*} other The other value to compare.
  6. * @param {Function} [fn] The function to customize comparisons.
  7. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  8. * @example
  9. *
  10. * function isGreeting(value) {
  11. * return /^h(?:i|ello)$/.test(value);
  12. * }
  13. *
  14. * function customizer(objValue, othValue) {
  15. * if (isGreeting(objValue) && isGreeting(othValue)) {
  16. * return true;
  17. * }
  18. * }
  19. *
  20. * var array = ['hello', 'goodbye'];
  21. * var other = ['hi', 'goodbye'];
  22. *
  23. * isEqualWith(array, other, customizer); // => true
  24. */
  25. var isEqualWith = function isEqualWith(value, other, fn) {
  26. if (!isFunction(fn)) {
  27. return isEqual(value, other);
  28. }
  29. return !!fn(value, other);
  30. };
  31. module.exports = isEqualWith;