omnibelt/eq-paths.js

  1. const pipe = require('ramda/src/pipe');
  2. const curry = require('ramda/src/curry');
  3. const path = require('ramda/src/path');
  4. const map = require('ramda/src/map');
  5. const apply = require('ramda/src/apply');
  6. const equals = require('ramda/src/equals');
  7. /**
  8. * Takes a path to check and two objects and checks if the value at that path
  9. * is equal for both objects.
  10. *
  11. * @signature Array<String> -> Object -> Object -> Boolean
  12. */
  13. const eqPaths = curry((pathToCheck, a, b) =>
  14. pipe(
  15. map(path(pathToCheck)),
  16. apply(equals)
  17. )([a, b])
  18. );
  19. module.exports = eqPaths;