@huluvu424242/honey-slideshow
Version:
Text to Speech component wich is reading texts from DOM elements.
79 lines (78 loc) • 2.49 kB
JavaScript
var Config = /** @class */ (function () {
function Config() {
this.m = new Map();
}
Config.prototype.reset = function (configObj) {
this.m = new Map(Object.entries(configObj));
};
Config.prototype.get = function (key, fallback) {
var value = this.m.get(key);
return (value !== undefined) ? value : fallback;
};
Config.prototype.getBoolean = function (key, fallback) {
if (fallback === void 0) { fallback = false; }
var val = this.m.get(key);
if (val === undefined) {
return fallback;
}
if (typeof val === 'string') {
return val === 'true';
}
return !!val;
};
Config.prototype.getNumber = function (key, fallback) {
var val = parseFloat(this.m.get(key));
return isNaN(val) ? (fallback !== undefined ? fallback : NaN) : val;
};
Config.prototype.set = function (key, value) {
this.m.set(key, value);
};
return Config;
}());
var config = /*@__PURE__*/ new Config();
var configFromSession = function (win) {
try {
var configStr = win.sessionStorage.getItem(IONIC_SESSION_KEY);
return configStr !== null ? JSON.parse(configStr) : {};
}
catch (e) {
return {};
}
};
var saveConfig = function (win, c) {
try {
win.sessionStorage.setItem(IONIC_SESSION_KEY, JSON.stringify(c));
}
catch (e) {
return;
}
};
var configFromURL = function (win) {
var configObj = {};
win.location.search.slice(1)
.split('&')
.map(function (entry) { return entry.split('='); })
.map(function (_a) {
var key = _a[0], value = _a[1];
return [decodeURIComponent(key), decodeURIComponent(value)];
})
.filter(function (_a) {
var key = _a[0];
return startsWith(key, IONIC_PREFIX);
})
.map(function (_a) {
var key = _a[0], value = _a[1];
return [key.slice(IONIC_PREFIX.length), value];
})
.forEach(function (_a) {
var key = _a[0], value = _a[1];
configObj[key] = value;
});
return configObj;
};
var startsWith = function (input, search) {
return input.substr(0, search.length) === search;
};
var IONIC_PREFIX = 'ionic:';
var IONIC_SESSION_KEY = 'ionic-persist-config';
export { configFromURL as a, config as b, configFromSession as c, saveConfig as s };