UNPKG

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