pathEq.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import _curry3 from "./internal/_curry3.js";
  2. import equals from "./equals.js";
  3. import path from "./path.js";
  4. /**
  5. * Determines whether a nested path on an object has a specific value, in
  6. * [`R.equals`](#equals) terms. Most likely used to filter a list.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.7.0
  11. * @category Relation
  12. * @typedefn Idx = String | Int | Symbol
  13. * @sig a -> [Idx] -> {a} -> Boolean
  14. * @param {*} val The value to compare the nested property with
  15. * @param {Array} path The path of the nested property to use
  16. * @param {Object} obj The object to check the nested property in
  17. * @return {Boolean} `true` if the value equals the nested object property,
  18. * `false` otherwise.
  19. * @see R.whereEq, R.propEq, R.pathSatisfies, R.equals
  20. * @example
  21. *
  22. * const user1 = { address: { zipCode: 90210 } };
  23. * const user2 = { address: { zipCode: 55555 } };
  24. * const user3 = { name: 'Bob' };
  25. * const users = [ user1, user2, user3 ];
  26. * const isFamous = R.pathEq(90210, ['address', 'zipCode']);
  27. * R.filter(isFamous, users); //=> [ user1 ]
  28. */
  29. var pathEq =
  30. /*#__PURE__*/
  31. _curry3(function pathEq(val, _path, obj) {
  32. return equals(path(_path, obj), val);
  33. });
  34. export default pathEq;