Compare commits

..

4 Commits

Author SHA1 Message Date
16048fe96d 4.0.4 2020-10-05 16:20:27 +00:00
04d60333a9 fix(core): update 2020-10-05 16:20:27 +00:00
c30f1f4ab9 4.0.3 2020-10-05 15:28:30 +00:00
fc91dd3171 fix(core): update 2020-10-05 15:28:29 +00:00
3 changed files with 13 additions and 4 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartjson",
"version": "4.0.2",
"version": "4.0.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartjson",
"version": "4.0.2",
"version": "4.0.4",
"private": false,
"description": "typed json handlers",
"main": "dist_ts/index.js",

View File

@ -10,7 +10,7 @@ export const parse = plugins.bufferJson.parse;
* @param objArg
* @param optionsArg
*/
export const stringify = (objArg: any, optionsArg: plugins.IStableJsonTypes['Options'] = {}) => {
export const stringify = (objArg: any, optionsArg: plugins.IStableJsonTypes['Options'] = {}): string => {
const bufferedJson = plugins.bufferJson.stringify(objArg);
objArg = JSON.parse(bufferedJson);
return plugins.stableJson(objArg, optionsArg);
@ -49,8 +49,17 @@ export class Smartjson {
*/
public foldToObject() {
const newFoldedObject: { [key: string]: any } = {};
const trackMap = [];
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;
}