toPlainObject.js 744 B

123456789101112131415161718192021222324252627282930313233
  1. var copyObject = require('./_copyObject'),
  2. keysIn = require('./keysIn');
  3. /**
  4. * Converts `value` to a plain object flattening inherited enumerable string
  5. * keyed properties of `value` to own properties of the plain object.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 3.0.0
  10. * @category Lang
  11. * @param {*} value The value to convert.
  12. * @returns {Object} Returns the converted plain object.
  13. * @example
  14. *
  15. * function Foo() {
  16. * this.b = 2;
  17. * }
  18. *
  19. * Foo.prototype.c = 3;
  20. *
  21. * _.assign({ 'a': 1 }, new Foo);
  22. * // => { 'a': 1, 'b': 2 }
  23. *
  24. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  25. * // => { 'a': 1, 'b': 2, 'c': 3 }
  26. */
  27. function toPlainObject(value) {
  28. return copyObject(value, keysIn(value));
  29. }
  30. module.exports = toPlainObject;