mirror of
https://github.com/maputnik/editor.git
synced 2026-09-02 02:17:26 +00:00
4d1e2e6893
This is basically the content of #841 with the code review changes and relevant fixes to tests/driver code to pass the tests. CC: @ShellyDCMS After this we should lint the project and add the lint to the CI to make sure it doesn't break. --------- Co-authored-by: ShellyDCMS <60476837+ShellyDCMS@users.noreply.github.com> Co-authored-by: shelly_goldblit <shelly_goldblit@dell.com>
49 lines
929 B
TypeScript
49 lines
929 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(debugStore.hasOwnProperty(namespace)) {
|
|
return debugStore[namespace][key];
|
|
}
|
|
}
|
|
|
|
const mod = {
|
|
enabled,
|
|
get,
|
|
set
|
|
};
|
|
|
|
(window as any).debug = mod;
|
|
export default mod;
|