diff options
Diffstat (limited to 'general-util.js')
-rw-r--r-- | general-util.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/general-util.js b/general-util.js index 4bfd491..364da88 100644 --- a/general-util.js +++ b/general-util.js @@ -349,3 +349,14 @@ export async function silenceEvents(emitter, eventsToSilence, callback) { emitter.emit = oldEmit } + +// Kindly stolen from ESDiscuss: +// https://esdiscuss.org/topic/proposal-add-an-option-to-omit-prototype-of-objects-created-by-json-parse#content-1 +export function parseWithoutPrototype(string) { + return JSON.parse(string, function(k, v) { + if (v && typeof v === 'object' && !Array.isArray(v)) { + return Object.assign(Object.create(null), v) + } + return v + }) +} |