diff --git a/rollup-full.config.mjs b/rollup-full.config.mjs index 51c41f78..79f5b4d0 100644 --- a/rollup-full.config.mjs +++ b/rollup-full.config.mjs @@ -88,7 +88,7 @@ export const terserPlugin = terser({ }, compress: { passes: 3, - pure_funcs: [ '_log', 'console.log'] + pure_funcs: [ 'debug', 'console.log'] } }); diff --git a/src/core/api.js b/src/core/api.js index bc96a662..0c607daf 100644 --- a/src/core/api.js +++ b/src/core/api.js @@ -4,7 +4,7 @@ import { appendChild, addClass, removeClass, - _log, + debug, getCurrentCategoriesState, elContains, setAcceptedCategories, @@ -212,7 +212,7 @@ export const show = (createModal) => { focus(globalObj._dom._cmDivTabindex); }, 100); - _log('CookieConsent [TOGGLE]: show consentModal'); + debug('CookieConsent [TOGGLE]: show consentModal'); fireEvent(globalObj._customEvents._onModalShow, CONSENT_MODAL_NAME); }; @@ -245,7 +245,7 @@ export const hide = () => { focus(_state._lastFocusedElemBeforeModal); _state._lastFocusedElemBeforeModal = null; - _log('CookieConsent [TOGGLE]: hide consentModal'); + debug('CookieConsent [TOGGLE]: hide consentModal'); fireEvent(_customEvents._onModalHide, CONSENT_MODAL_NAME); }; @@ -283,7 +283,7 @@ export const showPreferences = () => { focus(globalObj._dom._pmDivTabindex); }, 100); - _log('CookieConsent [TOGGLE]: show preferencesModal'); + debug('CookieConsent [TOGGLE]: show preferencesModal'); fireEvent(globalObj._customEvents._onModalShow, PREFERENCES_MODAL_NAME); }; @@ -354,7 +354,7 @@ export const hidePreferences = () => { state._lastFocusedElemBeforeModal = null; } - _log('CookieConsent [TOGGLE]: hide preferencesModal'); + debug('CookieConsent [TOGGLE]: hide preferencesModal'); fireEvent(globalObj._customEvents._onModalHide, PREFERENCES_MODAL_NAME); }; @@ -499,7 +499,7 @@ export const setCookieData = (props) => { set = true; } } - }else if ((sameType || !cookieData) && cookieData !== newData) { + } else if ((sameType || !cookieData) && cookieData !== newData) { cookieData = newData; set = true; } @@ -606,7 +606,7 @@ const retrieveState = () => { state._invalidConsent && (localStorageManager._removeItem(config.cookie.name)); } - _log('CookieConsent [STATUS] valid consent:', !state._invalidConsent); + debug('CookieConsent [STATUS] valid consent:', !state._invalidConsent); retrieveEnabledCategoriesAndServices(); /** diff --git a/src/core/config-init.js b/src/core/config-init.js index 94481ae1..5dd76f6a 100644 --- a/src/core/config-init.js +++ b/src/core/config-init.js @@ -1,5 +1,5 @@ import { globalObj } from './global'; -import { _log, getKeys, isObject, retrieveScriptElements, fetchCategoriesAndServices } from '../utils/general'; +import { debug, getKeys, isObject, retrieveScriptElements, fetchCategoriesAndServices } from '../utils/general'; import { OPT_OUT_MODE } from '../utils/constants'; import { resolveCurrentLanguageCode, setCurrentLanguageCode } from '../utils/language'; @@ -102,10 +102,10 @@ export const setConfig = (userConfig) => { if (isObject(userCookieConfig)) config.cookie = {...cookie, ...userCookieConfig}; - _log('CookieConsent [CONFIG]: configuration:', userConfig); - _log('CookieConsent [CONFIG]: autoClearCookies:', config.autoClearCookies); - _log('CookieConsent [CONFIG]: revision enabled:', state._revisionEnabled); - _log('CookieConsent [CONFIG]: manageScriptTags:', config.manageScriptTags); + debug('CookieConsent [CONFIG]: configuration:', userConfig); + debug('CookieConsent [CONFIG]: autoClearCookies:', config.autoClearCookies); + debug('CookieConsent [CONFIG]: revision enabled:', state._revisionEnabled); + debug('CookieConsent [CONFIG]: manageScriptTags:', config.manageScriptTags); fetchCategoriesAndServices(allCategoryNames); retrieveScriptElements(); diff --git a/src/core/modals/consentModal.js b/src/core/modals/consentModal.js index 3b885c54..3da05c37 100644 --- a/src/core/modals/consentModal.js +++ b/src/core/modals/consentModal.js @@ -1,7 +1,7 @@ import { globalObj } from '../global'; import { - _log, + debug, createNode, addClass, addClassCm, @@ -119,7 +119,7 @@ export const createConsentModal = (api, createMainContainer) => { addClassCm(dom._cmCloseIconBtn, 'btn'); addClassCm(dom._cmCloseIconBtn, 'btn--close'); addEvent(dom._cmCloseIconBtn, CLICK_EVENT, () => { - _log('CookieConsent [ACCEPT]: necessary'); + debug('CookieConsent [ACCEPT]: necessary'); acceptAndHide([]); }); appendChild(dom._cmBody, dom._cmCloseIconBtn); @@ -180,7 +180,7 @@ export const createConsentModal = (api, createMainContainer) => { setAttribute(dom._cmAcceptAllBtn, DATA_ROLE, 'all'); addEvent(dom._cmAcceptAllBtn, CLICK_EVENT, () => { - _log('CookieConsent [ACCEPT]: all'); + debug('CookieConsent [ACCEPT]: all'); acceptAndHide('all'); }); } @@ -196,7 +196,7 @@ export const createConsentModal = (api, createMainContainer) => { setAttribute(dom._cmAcceptNecessaryBtn, DATA_ROLE, 'necessary'); addEvent(dom._cmAcceptNecessaryBtn, CLICK_EVENT, () => { - _log('CookieConsent [ACCEPT]: necessary'); + debug('CookieConsent [ACCEPT]: necessary'); acceptAndHide([]); }); } @@ -269,7 +269,7 @@ export const createConsentModal = (api, createMainContainer) => { if (!state._consentModalExists) { state._consentModalExists = true; - _log('CookieConsent [HTML] created', CONSENT_MODAL_NAME); + debug('CookieConsent [HTML] created', CONSENT_MODAL_NAME); fireEvent(globalObj._customEvents._onModalReady, CONSENT_MODAL_NAME, dom._cm); createMainContainer(api); diff --git a/src/core/modals/preferencesModal.js b/src/core/modals/preferencesModal.js index f7664761..73f1718d 100644 --- a/src/core/modals/preferencesModal.js +++ b/src/core/modals/preferencesModal.js @@ -16,7 +16,7 @@ import { fireEvent, getSvgIcon, handleFocusTrap, - _log + debug } from '../../utils/general'; import { guiManager } from '../../utils/gui-manager'; @@ -474,7 +474,7 @@ export const createPreferencesModal = (api, createMainContainer) => { if (!state._preferencesModalExists) { state._preferencesModalExists = true; - _log('CookieConsent [HTML] created', PREFERENCES_MODAL_NAME); + debug('CookieConsent [HTML] created', PREFERENCES_MODAL_NAME); fireEvent(globalObj._customEvents._onModalReady, PREFERENCES_MODAL_NAME, dom._pm); createMainContainer(api); @@ -590,10 +590,10 @@ function createToggleLabel(label, value, sCurrentCategoryObject, isService, cate if (isService) { const enabledServices = state._acceptedServices[categoryName]; toggle.checked = sCurrentCategoryObject.readOnly || elContains(enabledServices, value); - }else if (elContains(state._acceptedCategories, value)) { + } else if (elContains(state._acceptedCategories, value)) { toggle.checked = true; } - }else if (sCurrentCategoryObject.readOnly || sCurrentCategoryObject.enabled) { + } else if (sCurrentCategoryObject.readOnly || sCurrentCategoryObject.enabled) { toggle.checked = true; } diff --git a/src/utils/cookies.js b/src/utils/cookies.js index cd2fc499..63efe2ff 100644 --- a/src/utils/cookies.js +++ b/src/utils/cookies.js @@ -3,7 +3,7 @@ import { OPT_OUT_MODE, OPT_IN_MODE } from './constants'; import { manageExistingScripts } from './scripts'; import { - _log, + debug, indexOf, uuidv4, getRemainingExpirationTimeMS, @@ -269,7 +269,7 @@ export const setCookie = (useRemainingExpirationTime) => { ? localStorageManager._setItem(name, value) : document.cookie = cookieStr; - _log('CookieConsent [SET_COOKIE]: ' + name + ':', globalObj._state._savedCookieContent); + debug('CookieConsent [SET_COOKIE]: ' + name + ':', globalObj._state._savedCookieContent); }; /** @@ -335,7 +335,7 @@ export const eraseCookiesHelper = (cookies, customPath, customDomain) => { if (isWwwSubdomain) erase(cookieName, mainDomain); - _log('CookieConsent [AUTOCLEAR]: deleting cookie: "' + cookieName + '" path: "' + path + '" domain:', domain); + debug('CookieConsent [AUTOCLEAR]: deleting cookie: "' + cookieName + '" path: "' + path + '" domain:', domain); } }; diff --git a/src/utils/general.js b/src/utils/general.js index 1b865b1f..4466b09d 100644 --- a/src/utils/general.js +++ b/src/utils/general.js @@ -7,14 +7,10 @@ import { /** * Helper console.log function - * @param {Object} printMsg - * @param {Object} [optionalParam] + * @param {any} [params] */ -export const _log = (printMsg, optionalParam) => { - console.log(printMsg, optionalParam !== undefined - ? optionalParam - : ' ' - ); +export const debug = (...params) => { + console.log(...params); }; /** @@ -324,7 +320,7 @@ export const resolveEnabledCategories = (categories, excludedCategories) => { if (isArray(categories)) { enabledCategories.push(...categories); - }else if (isString(categories)) { + } else if (isString(categories)) { enabledCategories = categories === 'all' ? _allCategoryNames : [categories]; @@ -460,7 +456,7 @@ export const updateModalToggles = (service, category) => { } } } - }else if (isArray(service)) { + } else if (isArray(service)) { for (let serviceName of allServiceNames) { const validService = elContains(service, serviceName); validService && _enabledServices[category].push(serviceName); @@ -921,7 +917,7 @@ export const fireEvent = (eventName, modalName, modal) => { if (eventName === events._onModalShow) { isFunction(_onModalShow) && _onModalShow(modalParams); - }else if (eventName === events._onModalHide) { + } else if (eventName === events._onModalHide) { isFunction(_onModalHide) && _onModalHide(modalParams); } else { modalParams.modal = modal; @@ -938,9 +934,9 @@ export const fireEvent = (eventName, modalName, modal) => { if (eventName === events._onFirstConsent) { isFunction(_onFirstConsent) && _onFirstConsent(deepCopy(params)); - }else if (eventName === events._onConsent) { + } else if (eventName === events._onConsent) { isFunction(_onConsent) && _onConsent(deepCopy(params)); - }else { + } else { params.changedCategories = globalObj._state._lastChangedCategoryNames; params.changedServices = globalObj._state._lastChangedServices; isFunction(_onChange) && _onChange(deepCopy(params)); diff --git a/src/utils/language.js b/src/utils/language.js index c1353385..8308976b 100644 --- a/src/utils/language.js +++ b/src/utils/language.js @@ -1,6 +1,6 @@ import { globalObj } from '../core/global'; import { - _log, + debug, elContains, fetchJson, addClass, @@ -74,7 +74,7 @@ export const resolveCurrentLanguageCode = () => { const autoDetect = globalObj._state._userConfig.language.autoDetect; if (autoDetect) { - _log('CookieConsent [LANG]: autoDetect strategy: "' + autoDetect + '"'); + debug('CookieConsent [LANG]: autoDetect strategy: "' + autoDetect + '"'); const detectionStrategies = { browser: getBrowserLanguageCode(), @@ -128,7 +128,7 @@ export const loadTranslationData = async (desiredLanguageCode) => { state._currentTranslation = translationData; setCurrentLanguageCode(currentLanguageCode); - _log('CookieConsent [LANG]: set language: "' + currentLanguageCode + '"'); + debug('CookieConsent [LANG]: set language: "' + currentLanguageCode + '"'); return true; };