You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
744 B

4 years ago
  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;