Skip to content

Commit 9cfc3d9

Browse files
committed
feat(mixins): Add toPlainObject
1 parent 58a386b commit 9cfc3d9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"author": "Contentful <opensource@contentful.com>",
1111
"license": "MIT",
1212
"scripts": {
13-
"clean": "rimraf *.js && rimraf coverage && rimraf src/vendor-* && rimraf vendor-* && rimraf src/package.json",
13+
"clean": "rimraf *.js && rimraf coverage && rimraf src/vendor-* && rimraf mixins && rimraf vendor-* && rimraf src/package.json",
1414
"build": "npm run clean && npm run vendor && cp -r src/vendor-* . && npm run build:dist",
1515
"build:dist": "babel src --out-dir .",
1616
"test:ci": "npm run test:cover",

src/mixins/to-plain-object.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {cloneDeep} from 'lodash/lang'
2+
3+
/**
4+
* Mixes in a method to return just a plain object with no additional methods
5+
* @private
6+
* @param {Object} data - Any plain JSON response returned from the API
7+
* @return {Object} Enhanced object with toPlainObject method
8+
*/
9+
export default function mixinToPlainObject (data) {
10+
return Object.defineProperty(data, 'toPlainObject', {
11+
enumerable: false,
12+
configurable: false,
13+
writable: false,
14+
value: function () {
15+
return cloneDeep(this)
16+
}
17+
})
18+
}

0 commit comments

Comments
 (0)