« get me outta code hell

synchronize shared sources on join + other stuff - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/general-util.js
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-04-26 13:15:09 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-04-26 13:15:09 -0300
commit84c49e453336d6105655edd08e93bab071c0fc3b (patch)
tree4b65a3dd7d08c1652408b293c659fcef37347241 /general-util.js
parenta1aa060f848e7d8da29142954c4f642970fc3fab (diff)
synchronize shared sources on join + other stuff
Diffstat (limited to 'general-util.js')
-rw-r--r--general-util.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/general-util.js b/general-util.js
index 0f5bdd5..85ff8e5 100644
--- a/general-util.js
+++ b/general-util.js
@@ -324,3 +324,14 @@ module.exports.silenceEvents = async function(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
+module.exports.parseWithoutPrototype = function(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
+  })
+}