From 1a92101ba05a5bb91898371ba9175fdc4edcf491 Mon Sep 17 00:00:00 2001 From: Vladimir Skripkin Date: Mon, 9 Sep 2019 22:46:32 +0300 Subject: [PATCH 1/3] try to use "toJSON" method before converting named objects to string --- src/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/index.ts b/src/index.ts index c2258ea..1a16219 100644 --- a/src/index.ts +++ b/src/index.ts @@ -204,6 +204,19 @@ export default function devalue(value: any, level = defaultLogLevel) { break; default: + if (thing && thing.toJSON) { + let json = thing.toJSON(); + if (getType(json) === 'String') { + // Try to parse the returned data + try { + json = JSON.parse(json); + } catch (e) { + json = thing; + }; + } + thing = json; + } + values.push(Object.getPrototypeOf(thing) === null ? 'Object.create(null)' : '{}'); Object.keys(thing).forEach(key => { statements.push(`${name}${safeProp(key)}=${stringify(thing[key])}`); From 1f3de4c4d7ad869a516e250d3d16c8e139041d59 Mon Sep 17 00:00:00 2001 From: Vladimir Skripkin Date: Mon, 9 Sep 2019 22:47:19 +0300 Subject: [PATCH 2/3] 1.2.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e9c0caa..9dd3e0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nuxt/devalue", - "version": "1.2.4", + "version": "1.2.5", "description": "Gets the job done when JSON.stringify can't", "repository": "nuxt-community/devalue", "license": "MIT", From 74f11733bc60672e21517e09593c0023bd9639fe Mon Sep 17 00:00:00 2001 From: Vladimir Skripkin Date: Tue, 10 Sep 2019 13:39:48 +0300 Subject: [PATCH 3/3] revert version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9dd3e0e..e9c0caa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nuxt/devalue", - "version": "1.2.5", + "version": "1.2.4", "description": "Gets the job done when JSON.stringify can't", "repository": "nuxt-community/devalue", "license": "MIT",