Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

property.js 793B

1234567891011121314151617181920212223242526272829303132
  1. var baseProperty = require('./_baseProperty'),
  2. basePropertyDeep = require('./_basePropertyDeep'),
  3. isKey = require('./_isKey'),
  4. toKey = require('./_toKey');
  5. /**
  6. * Creates a function that returns the value at `path` of a given object.
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 2.4.0
  11. * @category Util
  12. * @param {Array|string} path The path of the property to get.
  13. * @returns {Function} Returns the new accessor function.
  14. * @example
  15. *
  16. * var objects = [
  17. * { 'a': { 'b': 2 } },
  18. * { 'a': { 'b': 1 } }
  19. * ];
  20. *
  21. * _.map(objects, _.property('a.b'));
  22. * // => [2, 1]
  23. *
  24. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  25. * // => [1, 2]
  26. */
  27. function property(path) {
  28. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  29. }
  30. module.exports = property;