From efbef7e8f54d3c4a7ce518a27e077e41c72094ba Mon Sep 17 00:00:00 2001 From: zefie Date: Sat, 15 Jan 2022 05:19:10 -0500 Subject: [PATCH] Add 'Object.getCaseInsensitiveKey()' prototype override --- zefie_wtvp_minisrv/app.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index 331d781e..c9438ed5 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -49,6 +49,19 @@ if (!String.prototype.reverse) { } } +// add .getCaseInsensitiveKey() to all JavaScript Objects in this application { +// works for service vault scripts too. + +if (!Object.prototype.getCaseInsensitiveKey) { + Object.prototype.getCaseInsensitiveKey = function (object_name, key_name) { + var foundKey = Object.keys(object_name).find(key => key.toLowerCase() === key_name.toLowerCase()) || null; + if (foundKey) { + // found a key + return object_name[foundKey]; + } else return null; + } +} + function getServiceString(service, overrides = {}) { // used externally by service scripts if (service === "all") {