Skip to content

Commit

Permalink
refactor(logger): prevent side-effects
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadhonarvar committed Oct 11, 2024
1 parent f92eeed commit e084894
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions packages/logger/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@ import type {AlwatrLogger} from './type.js';
__dev_mode__: packageTracer.add(__package_name__, __package_version__);

const defaultDebugMode = /* #__PURE__ */ (() => {
return platformInfo.development ||
(platformInfo.isCli
? Boolean(process.env.DEBUG)
: typeof localStorage !== 'undefined' && localStorage.getItem('ALWATR_DEBUG') === '1');
return (
platformInfo.development ||
(platformInfo.isCli ? Boolean(process.env.DEBUG) : typeof localStorage !== 'undefined' && localStorage.getItem('ALWATR_DEBUG') === '1')
);
})();

/**
* Color list storage for logger.
*/
const colorList = platformInfo.isCli
? ['0;36', '0;35', '0;34', '0;33', '0;32'] // red and white omitted
: [
'#35b997',
'#f05561',
'#ee224a',
'#91c13e',
'#22af4b',
'#f0e995',
'#0fe995',
'#0f89ca',
'#08b9a5',
'#fee851',
'#ee573d',
'#f9df30',
'#1da2dc',
'#f05123',
'#ee2524',
];
const colorList = /* #__PURE__ */ (() =>
platformInfo.isCli
? ['0;36', '0;35', '0;34', '0;33', '0;32'] // red and white omitted
: [
'#35b997',
'#f05561',
'#ee224a',
'#91c13e',
'#22af4b',
'#f0e995',
'#0fe995',
'#0f89ca',
'#08b9a5',
'#fee851',
'#ee573d',
'#f9df30',
'#1da2dc',
'#f05123',
'#ee2524',
])();

let _colorIndex = 0;
const _getNextColor = (): string => {
Expand All @@ -45,12 +46,12 @@ const _getNextColor = (): string => {
return color;
};

const _style = {
const _style = /* #__PURE__ */ (() => ({
scope: platformInfo.isCli ? '\x1b[{{color}}m' : 'color: {{color}};',
reset: platformInfo.isCli ? '\x1b[0m' : 'color: inherit;',
};
}))();

const _keySection = platformInfo.isCli ? '%s%s%s' : '%c%s%c';
const _keySection = /* #__PURE__ */ (() => (platformInfo.isCli ? '%s%s%s' : '%c%s%c'))();

const _sanitizeDomain = (domain: string): string => {
domain = domain.trim();
Expand Down

0 comments on commit e084894

Please sign in to comment.