if (typeof Conf[parameterName] === "undefined") {
Conf[parameterName] = defaultValue;
} else if (typeof Conf[parameterName] !== typeof defaultValue) {
- alert("Head's up - configuration " + parameterName + " does not have the right type. It should be a " + (typeof defaultValue) + ", it is a " + (typeof Conf[parameterName]));
+ myAlert("Head's up - configuration " + parameterName + " does not have the right type. It should be a " + (typeof defaultValue) + ", it is a " + (typeof Conf[parameterName]));
throw new Error("Wrong type for configuration " + parameterName + ", expected " + (typeof defaultValue) + ", got " + (typeof Conf[parameterName]));
}
}
}
function getSetting(key) {
- let type = undefined;
- let value = undefined;
+ let type;
+ let value;
/* get default value from configuration */
if (Object.prototype.hasOwnProperty.call(Conf, key)) {
value = localStorage.getItem(key);
/* get type from localStorage if no default is set */
- if (type === undefined) {
+ if (typeof type === "undefined") {
if (Object.prototype.hasOwnProperty.call(localStorage, key + "_key")) {
type = localStorage.getItem(key + "_type");
} else {
}
function setSetting(key, value) {
- let type = undefined;
+ let type;
/* try to retrieve type from configuration */
if (Object.prototype.hasOwnProperty.call(Conf, key)) {
}
/* try to retrieve type from localstorage */
- if (type === undefined) {
+ if (typeof type === "undefined") {
if (Object.prototype.hasOwnProperty.call(localStorage, key)) {
type = localStorage.getItem(key + "_type");
}
}
/* if not set type is defined from value */
- if (type === undefined) {
+ if (typeof type === "undefined") {
type = typeof value;
}
/* storage value in localstorage */
- if (type !== typeof value) {
- console.error("incoherent type");
- } else {
+ if (type === typeof value) {
if (type === "object") {
value = JSON.stringify(value);
}
} else {
console.error("Unsupported type");
}
+ } else {
+ console.error("incoherent type");
}
}