MCPcopy
hub / github.com/orestbida/cookieconsent / configAsString

Function configAsString

playground/src/modules/downloadConfig.js:11–41  ·  view source on GitHub ↗
({minify = false} = {})

Source from the content-addressed store, hash-verified

9const downloadBtn = getById('downloadConfigBtn');
10
11const configAsString = async ({minify = false} = {}) => {
12 const latest = await fetchLatestRelease();
13
14 let scriptStr = `import 'https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@${latest}/dist/cookieconsent.umd.js';\n\n`;
15
16 const state = getState();
17 const config = getCurrentUserConfig(state);
18 const darkModeEnabled = state._theme === 'cc--darkmode';
19
20 if (darkModeEnabled) {
21 scriptStr += '// Enable dark mode\n';
22 scriptStr += 'document.documentElement.classList.add(\'cc--darkmode\');\n\n';
23 }
24
25 /**
26 * Config. as string
27 */
28 let configStr = JSON.stringify(config, minify ? undefined : null, minify ? undefined : 4);
29
30 /**
31 * Remove double quotes from keys
32 */
33 configStr = unquoteJson(configStr);
34
35 /**
36 * Append config.
37 */
38 scriptStr += `CookieConsent.run(${configStr});`;
39
40 return scriptStr;
41};
42
43addEvent(downloadBtn, 'click', async () => {
44 const config = await configAsString();

Callers 1

downloadConfig.jsFile · 0.85

Calls 4

fetchLatestReleaseFunction · 0.90
getStateFunction · 0.90
getCurrentUserConfigFunction · 0.90
unquoteJsonFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…