mirror of
https://github.com/maputnik/editor.git
synced 2025-12-08 07:10:00 +00:00
Adds lint to CI and fixes errors. I'm not sure I'm fully proud of all the solutions there. But there's no lint issues and the lint is being checked as part of the CI. --------- Co-authored-by: Yuri Astrakhan <yuriastrakhan@gmail.com>
49 lines
952 B
TypeScript
49 lines
952 B
TypeScript
interface DebugStore {
|
|
[namespace: string]: {
|
|
[key: string]: any
|
|
}
|
|
}
|
|
|
|
const debugStore: DebugStore = {};
|
|
|
|
function enabled() {
|
|
const qs = new URL(window.location.href).searchParams;
|
|
const debugQs = qs.get("debug");
|
|
if(debugQs) {
|
|
return !!debugQs.match(/^(|1|true)$/);
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function genErr() {
|
|
return new Error("Debug not enabled, enable by appending '?debug' to your query string");
|
|
}
|
|
|
|
function set(namespace: keyof DebugStore, key: string, value: any) {
|
|
if(!enabled()) {
|
|
throw genErr();
|
|
}
|
|
debugStore[namespace] = debugStore[namespace] || {};
|
|
debugStore[namespace][key] = value;
|
|
}
|
|
|
|
function get(namespace: keyof DebugStore, key: string) {
|
|
if(!enabled()) {
|
|
throw genErr();
|
|
}
|
|
if(Object.prototype.hasOwnProperty.call(debugStore, namespace)) {
|
|
return debugStore[namespace][key];
|
|
}
|
|
}
|
|
|
|
const mod = {
|
|
enabled,
|
|
get,
|
|
set
|
|
};
|
|
|
|
(window as any).debug = mod;
|
|
export default mod;
|