@alwatr/logger 9.2.1 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/package.json +6 -6
package/dist/main.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/* 📦 @alwatr/logger v9.
|
|
1
|
+
/* 📦 @alwatr/logger v9.3.0 */
|
|
2
2
|
import{getGlobalThis as X}from"@alwatr/global-this";import{platformInfo as F}from"@alwatr/platform-info";var j=X().console,Y=(()=>{if(F.development)if(F.isCli)return process.env.ALWATR_DEBUG!=="0";else return typeof localStorage<"u"&&localStorage.getItem("ALWATR_DEBUG")!=="0";return F.isCli?Boolean(process.env.DEBUG):typeof localStorage<"u"&&localStorage.getItem("ALWATR_DEBUG")==="1"})(),R=(()=>F.isCli?["0;36","0;35","0;34","0;33","0;32"]:["#35b997","#f05561","#ee224a","#91c13e","#22af4b","#f0e995","#0fe995","#0f89ca","#08b9a5","#fee851","#ee573d","#f9df30","#1da2dc","#f05123","#ee2524"])(),B=(()=>({scope:F.isCli?"\x1B[{{color}}m":"color: {{color}};",reset:F.isCli?"\x1B[0m":"color: inherit;"}))(),J=(()=>F.isCli?"%s%s%s":"%c%s%c")(),O=0;function Z(){let H=R[O];return O=(O+1)%R.length,H}function $(H){if(H=H.trim(),!/^[[{<]/.test(H))H=`{${H}}`;return H}function G(H,P=Y){let W=Z(),E=B.scope.replace("{{color}}",W),A=$(H),Q={debugMode:P,banner:F.isCli?j.log.bind(j,`\x1B[1;37;45m {{{ %s }}} ${B.reset}`):j.log.bind(j,"%c%s","font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;"),accident:F.isCli?j.warn.bind(j,`${E}⚠️
|
|
3
3
|
%s\x1B[33m.%s() Accident \`%s\`!${B.reset}`,A):j.warn.bind(j,"%c%s%c.%s() Accident `%s`!",E,A,B.reset),error:F.isCli?j.error.bind(j,`${E}❌
|
|
4
4
|
%s\x1B[31m.%s() Error \`%s\`${B.reset}
|
|
5
5
|
`,A):j.error.bind(j,"%c%s%c.%s() Error `%s`\n",E,A,B.reset)};if(!P)return Q;return{...Q,logProperty:j.debug.bind(j,J+".%s = %o;",E,A,B.reset),logMethod:j.debug.bind(j,J+".%s();",E,A,B.reset),logFileModule:j.debug.bind(j,J+"/%s.js;",E,A,B.reset),logMethodArgs:j.debug.bind(j,J+".%s(%o);",E,A,B.reset),logMethodFull:j.debug.bind(j,J+".%s(%o) => %o",E,A,B.reset),logStep:j.debug.bind(j,J+".%s() -> %s",E,A,B.reset),logOther:j.debug.bind(j,J,E,A,B.reset),logTable:j.table.bind(j),incident:F.isCli?j.log.bind(j,`${E}\uD83D\uDEB8
|
|
6
6
|
%s${B.reset}.%s() Incident \`%s\`!${B.reset}`,A):j.log.bind(j,"%c%s%c.%s() Incident `%s`!",E,A,"color: orange;"),time:(K)=>j.time(A+"."+K),timeEnd:(K)=>j.timeEnd(A+"."+K)}}export{G as createLogger};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
8
|
+
//# debugId=BE5B94E7350333E764756E2164756E21
|
|
9
9
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
"import {getGlobalThis} from '@alwatr/global-this';\nimport {platformInfo} from '@alwatr/platform-info';\n\nimport type {AlwatrLogger} from './type.js';\n\nconst console_ = getGlobalThis().console;\n\n/**\n * Default debug mode state, determined by environment variables or localStorage.\n */\nconst defaultDebugMode = (() => {\n if (platformInfo.development) {\n if (platformInfo.isCli) {\n return process.env.ALWATR_DEBUG !== '0';\n }\n else {\n return typeof localStorage !== 'undefined' && localStorage.getItem('ALWATR_DEBUG') !== '0';\n }\n }\n // else\n return platformInfo.isCli\n ? Boolean(process.env.DEBUG)\n : typeof localStorage !== 'undefined' && localStorage.getItem('ALWATR_DEBUG') === '1';\n})();\n\n/**\n * A list of aesthetically pleasing colors for console logging, adapted for CLI and browser environments.\n */\nconst colorList = (() =>\n platformInfo.isCli\n ? ['0;36', '0;35', '0;34', '0;33', '0;32'] // CLI-safe colors\n : [\n '#35b997',\n '#f05561',\n '#ee224a',\n '#91c13e',\n '#22af4b',\n '#f0e995',\n '#0fe995',\n '#0f89ca',\n '#08b9a5',\n '#fee851',\n '#ee573d',\n '#f9df30',\n '#1da2dc',\n '#f05123',\n '#ee2524',\n ])();\n\n/**\n * Platform-specific styling templates for logger output.\n */\nconst style_ = (() => ({\n scope: platformInfo.isCli ? '\\x1b[{{color}}m' : 'color: {{color}};',\n reset: platformInfo.isCli ? '\\x1b[0m' : 'color: inherit;',\n}))();\n\n/**\n * Platform-specific format for displaying the logger's scope.\n */\nconst keySection_ = (() => (platformInfo.isCli ? '%s%s%s' : '%c%s%c'))();\n\n// --- Utility Functions ---\n\nlet colorIndex_ = 0;\n/**\n * Cycles through the `colorList` to provide a new color for each logger instance.\n */\nfunction getNextColor_(): string {\n const color = colorList[colorIndex_];\n colorIndex_ = (colorIndex_ + 1) % colorList.length;\n return color;\n}\n\n/**\n * Sanitizes and formats the logger domain string by wrapping it in brackets if not already.\n */\nfunction sanitizeDomain_(domain: string): string {\n domain = domain.trim();\n if (!/^[[{<]/.test(domain)) {\n domain = `{${domain}}`;\n }\n return domain;\n}\n\n// --- Core Factory ---\n\n/**\n * Create a logger function for fancy console debug with custom scope.\n *\n * - `color` is optional and automatically selected from an internal list.\n * - `debug` is optional and automatically detected from `ALWATR_DEBUG` in localStorage or `process.env.DEBUG`.\n *\n * @example\n * ```ts\n * import {createLogger} from '@alwatr/logger';\n * const logger = createLogger('my-module');\n *\n * logger.logMethodArgs?.('myMethod', {a: 1}); // This line is ignored if debugMode is false.\n * ```\n */\nexport function createLogger(domain: string, debugMode = defaultDebugMode): AlwatrLogger {\n const color = getNextColor_();\n const styleScope = style_.scope.replace('{{color}}', color);\n const sanitizedDomain = sanitizeDomain_(domain);\n\n /**\n * Logger methods that are always available, regardless of debugMode.\n */\n const requiredItems: AlwatrLogger = {\n debugMode,\n\n banner: platformInfo.isCli\n ? console_.log.bind(console_, `\\x1b[1;37;45m {{{ %s }}} ${style_.reset}`)\n : console_.log.bind(\n console_,\n '%c%s',\n 'font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;',\n ),\n\n accident: platformInfo.isCli\n ? console_.warn.bind(console_, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\`!${style_.reset}`, sanitizedDomain)\n : console_.warn.bind(console_, '%c%s%c.%s() Accident `%s`!', styleScope, sanitizedDomain, style_.reset),\n\n error: platformInfo.isCli\n ? console_.error.bind(console_, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${style_.reset}\\n`, sanitizedDomain)\n : console_.error.bind(console_, '%c%s%c.%s() Error `%s`\\n', styleScope, sanitizedDomain, style_.reset),\n };\n\n if (!debugMode) {\n return requiredItems;\n }\n\n /**\n * Logger methods available only when debugMode is true.\n * Using `console.debug` which is often filtered by default in browsers unless \"Verbose\" logs are enabled.\n */\n return {\n ...requiredItems,\n\n logProperty: console_.debug.bind(console_, keySection_ + '.%s = %o;', styleScope, sanitizedDomain, style_.reset),\n\n logMethod: console_.debug.bind(console_, keySection_ + '.%s();', styleScope, sanitizedDomain, style_.reset),\n\n logFileModule: console_.debug.bind(console_, keySection_ + '/%s.js;', styleScope, sanitizedDomain, style_.reset),\n\n logMethodArgs: console_.debug.bind(console_, keySection_ + '.%s(%o);', styleScope, sanitizedDomain, style_.reset),\n\n logMethodFull: console_.debug.bind(console_, keySection_ + '.%s(%o) => %o', styleScope, sanitizedDomain, style_.reset),\n\n logStep: console_.debug.bind(console_, keySection_ + '.%s() -> %s', styleScope, sanitizedDomain, style_.reset),\n\n logOther: console_.debug.bind(console_, keySection_, styleScope, sanitizedDomain, style_.reset),\n\n logTable: console_.table.bind(console_),\n\n incident: platformInfo.isCli\n ? console_.log.bind(console_, `${styleScope}🚸\\n%s${style_.reset}.%s() Incident \\`%s\\`!${style_.reset}`, sanitizedDomain)\n : console_.log.bind(console_, '%c%s%c.%s() Incident `%s`!', styleScope, sanitizedDomain, 'color: orange;'),\n\n time: (label: string) => console_.time(sanitizedDomain + '.' + label),\n timeEnd: (label: string) => console_.timeEnd(sanitizedDomain + '.' + label),\n } as const;\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAAA,wBAAQ,4BACR,uBAAQ,8BAIR,IAAM,EAAW,EAAc,EAAE,QAK3B,GAAoB,IAAM,CAC9B,GAAI,EAAa,YACf,GAAI,EAAa,MACf,OAAO,QAAQ,IAAI,eAAiB,IAGpC,YAAO,OAAO,aAAiB,KAAe,aAAa,QAAQ,cAAc,IAAM,IAI3F,OAAO,EAAa,MAChB,QAAQ,QAAQ,IAAI,KAAK,EACzB,OAAO,aAAiB,KAAe,aAAa,QAAQ,cAAc,IAAM,MACnF,EAKG,GAAa,IACjB,EAAa,MACT,CAAC,OAAQ,OAAQ,OAAQ,OAAQ,MAAM,EACvC,CACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,SACF,GAAG,EAKD,GAAU,KAAO,CACrB,MAAO,EAAa,MAAQ,kBAAoB,oBAChD,MAAO,EAAa,MAAQ,UAAY,iBAC1C,IAAI,EAKE,GAAe,IAAO,EAAa,MAAQ,SAAW,UAAW,EAInE,EAAc,EAIlB,SAAS,CAAa,EAAW,CAC/B,IAAM,EAAQ,EAAU,GAExB,OADA,GAAe,EAAc,GAAK,EAAU,OACrC,EAMT,SAAS,CAAe,CAAC,EAAwB,CAE/C,GADA,EAAS,EAAO,KAAK,EACjB,CAAC,SAAS,KAAK,CAAM,EACvB,EAAS,IAAI,KAEf,OAAO,EAmBF,SAAS,CAAY,CAAC,EAAgB,EAAY,EAAgC,CACvF,IAAM,EAAQ,EAAc,EACtB,EAAa,EAAO,MAAM,QAAQ,YAAa,CAAK,EACpD,E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KAAM,CAAC,IAAkB,EAAS,KAAK,EAAkB,IAAM,CAAK,EACpE,QAAS,CAAC,IAAkB,EAAS,QAAQ,EAAkB,IAAM,CAAK,CAC5E",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "BE5B94E7350333E764756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/logger",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
4
4
|
"description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@alwatr/global-this": "9.
|
|
25
|
-
"@alwatr/platform-info": "9.
|
|
24
|
+
"@alwatr/global-this": "9.3.0",
|
|
25
|
+
"@alwatr/platform-info": "9.3.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@alwatr/nano-build": "9.
|
|
29
|
-
"@alwatr/
|
|
28
|
+
"@alwatr/nano-build": "9.3.0",
|
|
29
|
+
"@alwatr/standard": "9.3.0",
|
|
30
30
|
"@alwatr/type-helper": "9.1.1",
|
|
31
31
|
"@types/node": "^24.12.2",
|
|
32
32
|
"typescript": "^6.0.2"
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"utility",
|
|
77
77
|
"utils"
|
|
78
78
|
],
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "adf6d486667eefee42dfc87938e3af96f87c4738"
|
|
80
80
|
}
|