js-config-loader
Advanced tools
@@ -60,3 +60,3 @@ class ConfigLoader { | ||
| throwError = false | ||
| }) { | ||
| } = {}) { | ||
| this.element = element; | ||
@@ -63,0 +63,0 @@ this.throwError = throwError; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"loader.esm.js","sources":["../src/index.js"],"sourcesContent":["export default class ConfigLoader {\n /**\n *\n * @return {*}\n */\n get config() {\n if (this._config !== undefined) {\n return this._config;\n }\n\n let element;\n let elementId = this.element;\n\n if (elementId.substr(0, 1) === '#') {\n elementId = elementId.substr(1);\n }\n\n if (document === undefined) {\n if (this.throwError === true) {\n throw new Error('Can not find the document node to find configuration element \"' + this.element + '\".');\n }\n\n return {};\n }\n\n // try to find the user config element\n element = document.getElementById(elementId);\n if (element === null) {\n if (this.throwError === true) {\n throw new Error('Can not find the Element \"' + this.element + '\" for configuration.');\n }\n\n return {};\n }\n\n // try to parse the JSON from element\n try {\n this._config = JSON.parse(element.innerHTML);\n }\n catch (exception) {\n if (this.throwError === true) {\n throw new Error('Can not parse the data from Element \"' + this.element + '\" for configuration.\\n' + (exception.message || exception));\n }\n\n return {};\n }\n\n\n return this._config;\n }\n\n /**\n * loads config from script type application json\n *\n * @param {String} element\n * @param {Boolean} [throwError = false]\n */\n constructor(element, {throwError = false}) {\n this.element = element;\n\n this.throwError = throwError;\n }\n}\n"],"names":["ConfigLoader","config","_config","undefined","element","elementId","substr","document","throwError","Error","getElementById","JSON","parse","innerHTML","exception","message","constructor"],"mappings":"AAAe,MAAMA,YAAN,CAAmB;;;;;MAK1BC,MAAJ,GAAa;QACL,KAAKC,OAAL,KAAiBC,SAArB,EAAgC;aACrB,KAAKD,OAAZ;;;QAGAE,OAAJ;QACIC,SAAS,GAAG,KAAKD,OAArB;;QAEIC,SAAS,CAACC,MAAV,CAAiB,CAAjB,EAAoB,CAApB,MAA2B,GAA/B,EAAoC;MAChCD,SAAS,GAAGA,SAAS,CAACC,MAAV,CAAiB,CAAjB,CAAZ;;;QAGAC,QAAQ,KAAKJ,SAAjB,EAA4B;UACpB,KAAKK,UAAL,KAAoB,IAAxB,EAA8B;cACpB,IAAIC,KAAJ,CAAU,mEAAmE,KAAKL,OAAxE,GAAkF,IAA5F,CAAN;;;aAGG,EAAP;KAjBK;;;IAqBTA,OAAO,GAAGG,QAAQ,CAACG,cAAT,CAAwBL,SAAxB,CAAV;;QACID,OAAO,KAAK,IAAhB,EAAsB;UACd,KAAKI,UAAL,KAAoB,IAAxB,EAA8B;cACpB,IAAIC,KAAJ,CAAU,+BAA+B,KAAKL,OAApC,GAA8C,sBAAxD,CAAN;;;aAGG,EAAP;KA3BK;;;QA+BL;WACKF,OAAL,GAAeS,IAAI,CAACC,KAAL,CAAWR,OAAO,CAACS,SAAnB,CAAf;KADJ,CAGA,OAAOC,SAAP,EAAkB;UACV,KAAKN,UAAL,KAAoB,IAAxB,EAA8B;cACpB,IAAIC,KAAJ,CAAU,0CAA0C,KAAKL,OAA/C,GAAyD,wBAAzD,IAAqFU,SAAS,CAACC,OAAV,IAAqBD,SAA1G,CAAV,CAAN;;;aAGG,EAAP;;;WAIG,KAAKZ,OAAZ;;;;;;;;;;EASJc,WAAW,CAACZ,OAAD,EAAU;IAACI,UAAU,GAAG;GAAxB,EAAgC;SAClCJ,OAAL,GAAeA,OAAf;SAEKI,UAAL,GAAkBA,UAAlB;;;;;;;"} | ||
| {"version":3,"file":"loader.esm.js","sources":["../src/index.js"],"sourcesContent":["export default class ConfigLoader {\n /**\n *\n * @return {*}\n */\n get config() {\n if (this._config !== undefined) {\n return this._config;\n }\n\n let element;\n let elementId = this.element;\n\n if (elementId.substr(0, 1) === '#') {\n elementId = elementId.substr(1);\n }\n\n if (document === undefined) {\n if (this.throwError === true) {\n throw new Error('Can not find the document node to find configuration element \"' + this.element + '\".');\n }\n\n return {};\n }\n\n // try to find the user config element\n element = document.getElementById(elementId);\n if (element === null) {\n if (this.throwError === true) {\n throw new Error('Can not find the Element \"' + this.element + '\" for configuration.');\n }\n\n return {};\n }\n\n // try to parse the JSON from element\n try {\n this._config = JSON.parse(element.innerHTML);\n }\n catch (exception) {\n if (this.throwError === true) {\n throw new Error('Can not parse the data from Element \"' + this.element + '\" for configuration.\\n' + (exception.message || exception));\n }\n\n return {};\n }\n\n\n return this._config;\n }\n\n /**\n * loads config from script type application json\n *\n * @param {String} element\n * @param {Boolean} [throwError = false]\n */\n constructor(element, {throwError = false} = {}) {\n this.element = element;\n\n this.throwError = throwError;\n }\n}\n"],"names":["ConfigLoader","config","_config","undefined","element","elementId","substr","document","throwError","Error","getElementById","JSON","parse","innerHTML","exception","message","constructor"],"mappings":"AAAe,MAAMA,YAAN,CAAmB;;;;;MAK1BC,MAAJ,GAAa;QACL,KAAKC,OAAL,KAAiBC,SAArB,EAAgC;aACrB,KAAKD,OAAZ;;;QAGAE,OAAJ;QACIC,SAAS,GAAG,KAAKD,OAArB;;QAEIC,SAAS,CAACC,MAAV,CAAiB,CAAjB,EAAoB,CAApB,MAA2B,GAA/B,EAAoC;MAChCD,SAAS,GAAGA,SAAS,CAACC,MAAV,CAAiB,CAAjB,CAAZ;;;QAGAC,QAAQ,KAAKJ,SAAjB,EAA4B;UACpB,KAAKK,UAAL,KAAoB,IAAxB,EAA8B;cACpB,IAAIC,KAAJ,CAAU,mEAAmE,KAAKL,OAAxE,GAAkF,IAA5F,CAAN;;;aAGG,EAAP;KAjBK;;;IAqBTA,OAAO,GAAGG,QAAQ,CAACG,cAAT,CAAwBL,SAAxB,CAAV;;QACID,OAAO,KAAK,IAAhB,EAAsB;UACd,KAAKI,UAAL,KAAoB,IAAxB,EAA8B;cACpB,IAAIC,KAAJ,CAAU,+BAA+B,KAAKL,OAApC,GAA8C,sBAAxD,CAAN;;;aAGG,EAAP;KA3BK;;;QA+BL;WACKF,OAAL,GAAeS,IAAI,CAACC,KAAL,CAAWR,OAAO,CAACS,SAAnB,CAAf;KADJ,CAGA,OAAOC,SAAP,EAAkB;UACV,KAAKN,UAAL,KAAoB,IAAxB,EAA8B;cACpB,IAAIC,KAAJ,CAAU,0CAA0C,KAAKL,OAA/C,GAAyD,wBAAzD,IAAqFU,SAAS,CAACC,OAAV,IAAqBD,SAA1G,CAAV,CAAN;;;aAGG,EAAP;;;WAIG,KAAKZ,OAAZ;;;;;;;;;;EASJc,WAAW,CAACZ,OAAD,EAAU;IAACI,UAAU,GAAG;MAAS,EAAjC,EAAqC;SACvCJ,OAAL,GAAeA,OAAf;SAEKI,UAAL,GAAkBA,UAAlB;;;;;;;"} |
@@ -1,1 +0,1 @@ | ||
| export default class{get config(){if(void 0!==this._config)return this._config;let t,r=this.element;if("#"===r.substr(0,1)&&(r=r.substr(1)),void 0===document){if(!0===this.throwError)throw new Error('Can not find the document node to find configuration element "'+this.element+'".');return{}}if(null===(t=document.getElementById(r))){if(!0===this.throwError)throw new Error('Can not find the Element "'+this.element+'" for configuration.');return{}}try{this._config=JSON.parse(t.innerHTML)}catch(t){if(!0===this.throwError)throw new Error('Can not parse the data from Element "'+this.element+'" for configuration.\n'+(t.message||t));return{}}return this._config}constructor(t,{throwError:r=!1}){this.element=t,this.throwError=r}}//# sourceMappingURL=loader.esm.min.js.map | ||
| export default class{get config(){if(void 0!==this._config)return this._config;let t,r=this.element;if("#"===r.substr(0,1)&&(r=r.substr(1)),void 0===document){if(!0===this.throwError)throw new Error('Can not find the document node to find configuration element "'+this.element+'".');return{}}if(null===(t=document.getElementById(r))){if(!0===this.throwError)throw new Error('Can not find the Element "'+this.element+'" for configuration.');return{}}try{this._config=JSON.parse(t.innerHTML)}catch(t){if(!0===this.throwError)throw new Error('Can not parse the data from Element "'+this.element+'" for configuration.\n'+(t.message||t));return{}}return this._config}constructor(t,{throwError:r=!1}={}){this.element=t,this.throwError=r}}//# sourceMappingURL=loader.esm.min.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"loader.esm.min.js","sources":["../src/index.js"],"sourcesContent":["export default class ConfigLoader {\n /**\n *\n * @return {*}\n */\n get config() {\n if (this._config !== undefined) {\n return this._config;\n }\n\n let element;\n let elementId = this.element;\n\n if (elementId.substr(0, 1) === '#') {\n elementId = elementId.substr(1);\n }\n\n if (document === undefined) {\n if (this.throwError === true) {\n throw new Error('Can not find the document node to find configuration element \"' + this.element + '\".');\n }\n\n return {};\n }\n\n // try to find the user config element\n element = document.getElementById(elementId);\n if (element === null) {\n if (this.throwError === true) {\n throw new Error('Can not find the Element \"' + this.element + '\" for configuration.');\n }\n\n return {};\n }\n\n // try to parse the JSON from element\n try {\n this._config = JSON.parse(element.innerHTML);\n }\n catch (exception) {\n if (this.throwError === true) {\n throw new Error('Can not parse the data from Element \"' + this.element + '\" for configuration.\\n' + (exception.message || exception));\n }\n\n return {};\n }\n\n\n return this._config;\n }\n\n /**\n * loads config from script type application json\n *\n * @param {String} element\n * @param {Boolean} [throwError = false]\n */\n constructor(element, {throwError = false}) {\n this.element = element;\n\n this.throwError = throwError;\n }\n}\n"],"names":["undefined","this","_config","element","elementId","substr","document","throwError","Error","getElementById","JSON","parse","innerHTML","exception","message","constructor"],"mappings":"eAAe,2BAMcA,IAAjBC,KAAKC,eACED,KAAKC,YAGZC,EACAC,EAAYH,KAAKE,WAEU,MAA3BC,EAAUC,OAAO,EAAG,KACpBD,EAAYA,EAAUC,OAAO,SAGhBL,IAAbM,SAAwB,KACA,IAApBL,KAAKM,iBACC,IAAIC,MAAM,iEAAmEP,KAAKE,QAAU,YAG/F,MAKK,QADhBA,EAAUG,SAASG,eAAeL,IACZ,KACM,IAApBH,KAAKM,iBACC,IAAIC,MAAM,6BAA+BP,KAAKE,QAAU,8BAG3D,YAKFD,QAAUQ,KAAKC,MAAMR,EAAQS,WAEtC,MAAOC,OACqB,IAApBZ,KAAKM,iBACC,IAAIC,MAAM,wCAA0CP,KAAKE,QAAU,0BAA4BU,EAAUC,SAAWD,UAGvH,UAIJZ,KAAKC,QAShBa,YAAYZ,GAASI,WAACA,GAAa,SAC1BJ,QAAUA,OAEVI,WAAaA"} | ||
| {"version":3,"file":"loader.esm.min.js","sources":["../src/index.js"],"sourcesContent":["export default class ConfigLoader {\n /**\n *\n * @return {*}\n */\n get config() {\n if (this._config !== undefined) {\n return this._config;\n }\n\n let element;\n let elementId = this.element;\n\n if (elementId.substr(0, 1) === '#') {\n elementId = elementId.substr(1);\n }\n\n if (document === undefined) {\n if (this.throwError === true) {\n throw new Error('Can not find the document node to find configuration element \"' + this.element + '\".');\n }\n\n return {};\n }\n\n // try to find the user config element\n element = document.getElementById(elementId);\n if (element === null) {\n if (this.throwError === true) {\n throw new Error('Can not find the Element \"' + this.element + '\" for configuration.');\n }\n\n return {};\n }\n\n // try to parse the JSON from element\n try {\n this._config = JSON.parse(element.innerHTML);\n }\n catch (exception) {\n if (this.throwError === true) {\n throw new Error('Can not parse the data from Element \"' + this.element + '\" for configuration.\\n' + (exception.message || exception));\n }\n\n return {};\n }\n\n\n return this._config;\n }\n\n /**\n * loads config from script type application json\n *\n * @param {String} element\n * @param {Boolean} [throwError = false]\n */\n constructor(element, {throwError = false} = {}) {\n this.element = element;\n\n this.throwError = throwError;\n }\n}\n"],"names":["undefined","this","_config","element","elementId","substr","document","throwError","Error","getElementById","JSON","parse","innerHTML","exception","message","constructor"],"mappings":"eAAe,2BAMcA,IAAjBC,KAAKC,eACED,KAAKC,YAGZC,EACAC,EAAYH,KAAKE,WAEU,MAA3BC,EAAUC,OAAO,EAAG,KACpBD,EAAYA,EAAUC,OAAO,SAGhBL,IAAbM,SAAwB,KACA,IAApBL,KAAKM,iBACC,IAAIC,MAAM,iEAAmEP,KAAKE,QAAU,YAG/F,MAKK,QADhBA,EAAUG,SAASG,eAAeL,IACZ,KACM,IAApBH,KAAKM,iBACC,IAAIC,MAAM,6BAA+BP,KAAKE,QAAU,8BAG3D,YAKFD,QAAUQ,KAAKC,MAAMR,EAAQS,WAEtC,MAAOC,OACqB,IAApBZ,KAAKM,iBACC,IAAIC,MAAM,wCAA0CP,KAAKE,QAAU,0BAA4BU,EAAUC,SAAWD,UAGvH,UAIJZ,KAAKC,QAShBa,YAAYZ,GAASI,WAACA,GAAa,GAAS,SACnCJ,QAAUA,OAEVI,WAAaA"} |
+3
-2
@@ -92,4 +92,5 @@ (function (global, factory) { | ||
| function ConfigLoader(element, _ref) { | ||
| var _ref$throwError = _ref.throwError, | ||
| function ConfigLoader(element) { | ||
| var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
| _ref$throwError = _ref.throwError, | ||
| throwError = _ref$throwError === void 0 ? false : _ref$throwError; | ||
@@ -96,0 +97,0 @@ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"loader.js","sources":["../src/index.js"],"sourcesContent":["export default class ConfigLoader {\n /**\n *\n * @return {*}\n */\n get config() {\n if (this._config !== undefined) {\n return this._config;\n }\n\n let element;\n let elementId = this.element;\n\n if (elementId.substr(0, 1) === '#') {\n elementId = elementId.substr(1);\n }\n\n if (document === undefined) {\n if (this.throwError === true) {\n throw new Error('Can not find the document node to find configuration element \"' + this.element + '\".');\n }\n\n return {};\n }\n\n // try to find the user config element\n element = document.getElementById(elementId);\n if (element === null) {\n if (this.throwError === true) {\n throw new Error('Can not find the Element \"' + this.element + '\" for configuration.');\n }\n\n return {};\n }\n\n // try to parse the JSON from element\n try {\n this._config = JSON.parse(element.innerHTML);\n }\n catch (exception) {\n if (this.throwError === true) {\n throw new Error('Can not parse the data from Element \"' + this.element + '\" for configuration.\\n' + (exception.message || exception));\n }\n\n return {};\n }\n\n\n return this._config;\n }\n\n /**\n * loads config from script type application json\n *\n * @param {String} element\n * @param {Boolean} [throwError = false]\n */\n constructor(element, {throwError = false}) {\n this.element = element;\n\n this.throwError = throwError;\n }\n}\n"],"names":["ConfigLoader","_config","undefined","element","elementId","substr","document","throwError","Error","getElementById","JSON","parse","innerHTML","exception","message"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAqBA;;;;;;EACjB;;;;0BAIa;EACT,UAAI,KAAKC,OAAL,KAAiBC,SAArB,EAAgC;EAC5B,eAAO,KAAKD,OAAZ;EACH;;EAED,UAAIE,OAAJ;EACA,UAAIC,SAAS,GAAG,KAAKD,OAArB;;EAEA,UAAIC,SAAS,CAACC,MAAV,CAAiB,CAAjB,EAAoB,CAApB,MAA2B,GAA/B,EAAoC;EAChCD,QAAAA,SAAS,GAAGA,SAAS,CAACC,MAAV,CAAiB,CAAjB,CAAZ;EACH;;EAED,UAAIC,QAAQ,KAAKJ,SAAjB,EAA4B;EACxB,YAAI,KAAKK,UAAL,KAAoB,IAAxB,EAA8B;EAC1B,gBAAM,IAAIC,KAAJ,CAAU,mEAAmE,KAAKL,OAAxE,GAAkF,IAA5F,CAAN;EACH;;EAED,eAAO,EAAP;EACH,OAlBQ;;;EAqBTA,MAAAA,OAAO,GAAGG,QAAQ,CAACG,cAAT,CAAwBL,SAAxB,CAAV;;EACA,UAAID,OAAO,KAAK,IAAhB,EAAsB;EAClB,YAAI,KAAKI,UAAL,KAAoB,IAAxB,EAA8B;EAC1B,gBAAM,IAAIC,KAAJ,CAAU,+BAA+B,KAAKL,OAApC,GAA8C,sBAAxD,CAAN;EACH;;EAED,eAAO,EAAP;EACH,OA5BQ;;;EA+BT,UAAI;EACA,aAAKF,OAAL,GAAeS,IAAI,CAACC,KAAL,CAAWR,OAAO,CAACS,SAAnB,CAAf;EACH,OAFD,CAGA,OAAOC,SAAP,EAAkB;EACd,YAAI,KAAKN,UAAL,KAAoB,IAAxB,EAA8B;EAC1B,gBAAM,IAAIC,KAAJ,CAAU,0CAA0C,KAAKL,OAA/C,GAAyD,wBAAzD,IAAqFU,SAAS,CAACC,OAAV,IAAqBD,SAA1G,CAAV,CAAN;EACH;;EAED,eAAO,EAAP;EACH;;EAGD,aAAO,KAAKZ,OAAZ;EACH;EAED;;;;;;;;;EAMA,wBAAYE,OAAZ,QAA2C;EAAA,+BAArBI,UAAqB;EAAA,QAArBA,UAAqB,gCAAR,KAAQ;;EAAA;;EACvC,SAAKJ,OAAL,GAAeA,OAAf;EAEA,SAAKI,UAAL,GAAkBA,UAAlB;EACH;;;;;;;;;;;"} | ||
| {"version":3,"file":"loader.js","sources":["../src/index.js"],"sourcesContent":["export default class ConfigLoader {\n /**\n *\n * @return {*}\n */\n get config() {\n if (this._config !== undefined) {\n return this._config;\n }\n\n let element;\n let elementId = this.element;\n\n if (elementId.substr(0, 1) === '#') {\n elementId = elementId.substr(1);\n }\n\n if (document === undefined) {\n if (this.throwError === true) {\n throw new Error('Can not find the document node to find configuration element \"' + this.element + '\".');\n }\n\n return {};\n }\n\n // try to find the user config element\n element = document.getElementById(elementId);\n if (element === null) {\n if (this.throwError === true) {\n throw new Error('Can not find the Element \"' + this.element + '\" for configuration.');\n }\n\n return {};\n }\n\n // try to parse the JSON from element\n try {\n this._config = JSON.parse(element.innerHTML);\n }\n catch (exception) {\n if (this.throwError === true) {\n throw new Error('Can not parse the data from Element \"' + this.element + '\" for configuration.\\n' + (exception.message || exception));\n }\n\n return {};\n }\n\n\n return this._config;\n }\n\n /**\n * loads config from script type application json\n *\n * @param {String} element\n * @param {Boolean} [throwError = false]\n */\n constructor(element, {throwError = false} = {}) {\n this.element = element;\n\n this.throwError = throwError;\n }\n}\n"],"names":["ConfigLoader","_config","undefined","element","elementId","substr","document","throwError","Error","getElementById","JSON","parse","innerHTML","exception","message"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAqBA;;;;;;EACjB;;;;0BAIa;EACT,UAAI,KAAKC,OAAL,KAAiBC,SAArB,EAAgC;EAC5B,eAAO,KAAKD,OAAZ;EACH;;EAED,UAAIE,OAAJ;EACA,UAAIC,SAAS,GAAG,KAAKD,OAArB;;EAEA,UAAIC,SAAS,CAACC,MAAV,CAAiB,CAAjB,EAAoB,CAApB,MAA2B,GAA/B,EAAoC;EAChCD,QAAAA,SAAS,GAAGA,SAAS,CAACC,MAAV,CAAiB,CAAjB,CAAZ;EACH;;EAED,UAAIC,QAAQ,KAAKJ,SAAjB,EAA4B;EACxB,YAAI,KAAKK,UAAL,KAAoB,IAAxB,EAA8B;EAC1B,gBAAM,IAAIC,KAAJ,CAAU,mEAAmE,KAAKL,OAAxE,GAAkF,IAA5F,CAAN;EACH;;EAED,eAAO,EAAP;EACH,OAlBQ;;;EAqBTA,MAAAA,OAAO,GAAGG,QAAQ,CAACG,cAAT,CAAwBL,SAAxB,CAAV;;EACA,UAAID,OAAO,KAAK,IAAhB,EAAsB;EAClB,YAAI,KAAKI,UAAL,KAAoB,IAAxB,EAA8B;EAC1B,gBAAM,IAAIC,KAAJ,CAAU,+BAA+B,KAAKL,OAApC,GAA8C,sBAAxD,CAAN;EACH;;EAED,eAAO,EAAP;EACH,OA5BQ;;;EA+BT,UAAI;EACA,aAAKF,OAAL,GAAeS,IAAI,CAACC,KAAL,CAAWR,OAAO,CAACS,SAAnB,CAAf;EACH,OAFD,CAGA,OAAOC,SAAP,EAAkB;EACd,YAAI,KAAKN,UAAL,KAAoB,IAAxB,EAA8B;EAC1B,gBAAM,IAAIC,KAAJ,CAAU,0CAA0C,KAAKL,OAA/C,GAAyD,wBAAzD,IAAqFU,SAAS,CAACC,OAAV,IAAqBD,SAA1G,CAAV,CAAN;EACH;;EAED,eAAO,EAAP;EACH;;EAGD,aAAO,KAAKZ,OAAZ;EACH;EAED;;;;;;;;;EAMA,wBAAYE,OAAZ,EAAgD;EAAA,mFAAJ,EAAI;EAAA,+BAA1BI,UAA0B;EAAA,QAA1BA,UAA0B,gCAAb,KAAa;;EAAA;;EAC5C,SAAKJ,OAAL,GAAeA,OAAf;EAEA,SAAKI,UAAL,GAAkBA,UAAlB;EACH;;;;;;;;;;;"} |
@@ -1,1 +0,1 @@ | ||
| !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).ConfigLoader=t()}(this,function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(){var t,n,r;function o(e,t){var n=t.throwError,r=void 0!==n&&n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),this.element=e,this.throwError=r}return t=o,(n=[{key:"config",get:function(){if(void 0!==this._config)return this._config;var e,t=this.element;if("#"===t.substr(0,1)&&(t=t.substr(1)),void 0===document){if(!0===this.throwError)throw new Error('Can not find the document node to find configuration element "'+this.element+'".');return{}}if(null===(e=document.getElementById(t))){if(!0===this.throwError)throw new Error('Can not find the Element "'+this.element+'" for configuration.');return{}}try{this._config=JSON.parse(e.innerHTML)}catch(e){if(!0===this.throwError)throw new Error('Can not parse the data from Element "'+this.element+'" for configuration.\n'+(e.message||e));return{}}return this._config}}])&&e(t.prototype,n),r&&e(t,r),o}()});//# sourceMappingURL=loader.min.js.map | ||
| !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).ConfigLoader=t()}(this,function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(){var t,n,r;function o(e){var t=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).throwError,n=void 0!==t&&t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),this.element=e,this.throwError=n}return t=o,(n=[{key:"config",get:function(){if(void 0!==this._config)return this._config;var e,t=this.element;if("#"===t.substr(0,1)&&(t=t.substr(1)),void 0===document){if(!0===this.throwError)throw new Error('Can not find the document node to find configuration element "'+this.element+'".');return{}}if(null===(e=document.getElementById(t))){if(!0===this.throwError)throw new Error('Can not find the Element "'+this.element+'" for configuration.');return{}}try{this._config=JSON.parse(e.innerHTML)}catch(e){if(!0===this.throwError)throw new Error('Can not parse the data from Element "'+this.element+'" for configuration.\n'+(e.message||e));return{}}return this._config}}])&&e(t.prototype,n),r&&e(t,r),o}()});//# sourceMappingURL=loader.min.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"loader.min.js","sources":["../src/index.js"],"sourcesContent":["export default class ConfigLoader {\n /**\n *\n * @return {*}\n */\n get config() {\n if (this._config !== undefined) {\n return this._config;\n }\n\n let element;\n let elementId = this.element;\n\n if (elementId.substr(0, 1) === '#') {\n elementId = elementId.substr(1);\n }\n\n if (document === undefined) {\n if (this.throwError === true) {\n throw new Error('Can not find the document node to find configuration element \"' + this.element + '\".');\n }\n\n return {};\n }\n\n // try to find the user config element\n element = document.getElementById(elementId);\n if (element === null) {\n if (this.throwError === true) {\n throw new Error('Can not find the Element \"' + this.element + '\" for configuration.');\n }\n\n return {};\n }\n\n // try to parse the JSON from element\n try {\n this._config = JSON.parse(element.innerHTML);\n }\n catch (exception) {\n if (this.throwError === true) {\n throw new Error('Can not parse the data from Element \"' + this.element + '\" for configuration.\\n' + (exception.message || exception));\n }\n\n return {};\n }\n\n\n return this._config;\n }\n\n /**\n * loads config from script type application json\n *\n * @param {String} element\n * @param {Boolean} [throwError = false]\n */\n constructor(element, {throwError = false}) {\n this.element = element;\n\n this.throwError = throwError;\n }\n}\n"],"names":["element","throwError","undefined","this","_config","elementId","substr","document","Error","getElementById","JSON","parse","innerHTML","exception","message"],"mappings":"+YAyDgBA,aAAUC,WAAAA,2HACbD,QAAUA,OAEVC,WAAaA,sDAtDGC,IAAjBC,KAAKC,eACED,KAAKC,YAGZJ,EACAK,EAAYF,KAAKH,WAEU,MAA3BK,EAAUC,OAAO,EAAG,KACpBD,EAAYA,EAAUC,OAAO,SAGhBJ,IAAbK,SAAwB,KACA,IAApBJ,KAAKF,iBACC,IAAIO,MAAM,iEAAmEL,KAAKH,QAAU,YAG/F,MAKK,QADhBA,EAAUO,SAASE,eAAeJ,IACZ,KACM,IAApBF,KAAKF,iBACC,IAAIO,MAAM,6BAA+BL,KAAKH,QAAU,8BAG3D,YAKFI,QAAUM,KAAKC,MAAMX,EAAQY,WAEtC,MAAOC,OACqB,IAApBV,KAAKF,iBACC,IAAIO,MAAM,wCAA0CL,KAAKH,QAAU,0BAA4Ba,EAAUC,SAAWD,UAGvH,UAIJV,KAAKC"} | ||
| {"version":3,"file":"loader.min.js","sources":["../src/index.js"],"sourcesContent":["export default class ConfigLoader {\n /**\n *\n * @return {*}\n */\n get config() {\n if (this._config !== undefined) {\n return this._config;\n }\n\n let element;\n let elementId = this.element;\n\n if (elementId.substr(0, 1) === '#') {\n elementId = elementId.substr(1);\n }\n\n if (document === undefined) {\n if (this.throwError === true) {\n throw new Error('Can not find the document node to find configuration element \"' + this.element + '\".');\n }\n\n return {};\n }\n\n // try to find the user config element\n element = document.getElementById(elementId);\n if (element === null) {\n if (this.throwError === true) {\n throw new Error('Can not find the Element \"' + this.element + '\" for configuration.');\n }\n\n return {};\n }\n\n // try to parse the JSON from element\n try {\n this._config = JSON.parse(element.innerHTML);\n }\n catch (exception) {\n if (this.throwError === true) {\n throw new Error('Can not parse the data from Element \"' + this.element + '\" for configuration.\\n' + (exception.message || exception));\n }\n\n return {};\n }\n\n\n return this._config;\n }\n\n /**\n * loads config from script type application json\n *\n * @param {String} element\n * @param {Boolean} [throwError = false]\n */\n constructor(element, {throwError = false} = {}) {\n this.element = element;\n\n this.throwError = throwError;\n }\n}\n"],"names":["element","throwError","undefined","this","_config","elementId","substr","document","Error","getElementById","JSON","parse","innerHTML","exception","message"],"mappings":"+YAyDgBA,iEAAgC,IAAtBC,WAAAA,2HACbD,QAAUA,OAEVC,WAAaA,sDAtDGC,IAAjBC,KAAKC,eACED,KAAKC,YAGZJ,EACAK,EAAYF,KAAKH,WAEU,MAA3BK,EAAUC,OAAO,EAAG,KACpBD,EAAYA,EAAUC,OAAO,SAGhBJ,IAAbK,SAAwB,KACA,IAApBJ,KAAKF,iBACC,IAAIO,MAAM,iEAAmEL,KAAKH,QAAU,YAG/F,MAKK,QADhBA,EAAUO,SAASE,eAAeJ,IACZ,KACM,IAApBF,KAAKF,iBACC,IAAIO,MAAM,6BAA+BL,KAAKH,QAAU,8BAG3D,YAKFI,QAAUM,KAAKC,MAAMX,EAAQY,WAEtC,MAAOC,OACqB,IAApBV,KAAKF,iBACC,IAAIO,MAAM,wCAA0CL,KAAKH,QAAU,0BAA4Ba,EAAUC,SAAWD,UAGvH,UAIJV,KAAKC"} |
+1
-1
| { | ||
| "name": "js-config-loader", | ||
| "version": "2.0.0", | ||
| "version": "2.0.1", | ||
| "description": "Loads json data from script of type json.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
+1
-1
@@ -58,3 +58,3 @@ export default class ConfigLoader { | ||
| */ | ||
| constructor(element, {throwError = false}) { | ||
| constructor(element, {throwError = false} = {}) { | ||
| this.element = element; | ||
@@ -61,0 +61,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25337
0.82%302
0.67%0
-100%