Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c30f1f4ab9 | |||
fc91dd3171 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartjson",
|
"name": "@pushrocks/smartjson",
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartjson",
|
"name": "@pushrocks/smartjson",
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "typed json handlers",
|
"description": "typed json handlers",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
11
ts/index.ts
11
ts/index.ts
@ -49,8 +49,17 @@ export class Smartjson {
|
|||||||
*/
|
*/
|
||||||
public foldToObject() {
|
public foldToObject() {
|
||||||
const newFoldedObject: { [key: string]: any } = {};
|
const newFoldedObject: { [key: string]: any } = {};
|
||||||
|
const trackMap = [];
|
||||||
for (const keyName of this.saveableProperties) {
|
for (const keyName of this.saveableProperties) {
|
||||||
newFoldedObject[keyName] = plugins.lodashCloneDeep(this[keyName]);
|
let value = this[keyName];
|
||||||
|
if (value instanceof Smartjson) {
|
||||||
|
if (trackMap.includes(value)) {
|
||||||
|
throw new Error('cycle detected');
|
||||||
|
}
|
||||||
|
trackMap.push(value);
|
||||||
|
value = value.foldToObject();
|
||||||
|
}
|
||||||
|
newFoldedObject[keyName] = plugins.lodashCloneDeep(value);
|
||||||
}
|
}
|
||||||
return newFoldedObject;
|
return newFoldedObject;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user