Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])}`);
Expand Down