chain.js 851 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var lodash = require('./wrapperLodash');
  2. /**
  3. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  4. * chain sequences enabled. The result of such sequences must be unwrapped
  5. * with `_#value`.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 1.3.0
  10. * @category Seq
  11. * @param {*} value The value to wrap.
  12. * @returns {Object} Returns the new `lodash` wrapper instance.
  13. * @example
  14. *
  15. * var users = [
  16. * { 'user': 'barney', 'age': 36 },
  17. * { 'user': 'fred', 'age': 40 },
  18. * { 'user': 'pebbles', 'age': 1 }
  19. * ];
  20. *
  21. * var youngest = _
  22. * .chain(users)
  23. * .sortBy('age')
  24. * .map(function(o) {
  25. * return o.user + ' is ' + o.age;
  26. * })
  27. * .head()
  28. * .value();
  29. * // => 'pebbles is 1'
  30. */
  31. function chain(value) {
  32. var result = lodash(value);
  33. result.__chain__ = true;
  34. return result;
  35. }
  36. module.exports = chain;