@alwatr/logger 1.1.5 → 2.0.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/CHANGELOG.md +24 -1
- package/define-package.d.ts +2 -0
- package/define-package.d.ts.map +1 -0
- package/define-package.js +18 -0
- package/define-package.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/logger.d.ts +0 -2
- package/logger.d.ts.map +1 -1
- package/logger.js +7 -10
- package/logger.js.map +1 -1
- package/package.json +4 -5
- package/type.d.ts +20 -4
- package/type.d.ts.map +1 -1
- package/type.js.map +1 -1
- package/global-alwatr.d.ts +0 -2
- package/global-alwatr.d.ts.map +0 -1
- package/global-alwatr.js +0 -17
- package/global-alwatr.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,11 +3,34 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.0.0](https://github.com/AliMD/alwatr-eslib/compare/@alwatr/logger@1.2.0...@alwatr/logger@2.0.0) (2023-10-23)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **logger:** remove globalAlwatr ([e7a7236](https://github.com/AliMD/alwatr-eslib/commit/e7a72361715cbeb05c5dea4dbff7c2b583d2eab2)) by @AliMD
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **logger:** define logger package ([5beaaf4](https://github.com/AliMD/alwatr-eslib/commit/5beaaf4f6f2f74d4976f9d0d58927526f283d5f9)) by @AliMD
|
|
15
|
+
* **logger:** definePackage, the new api for global alwatr ([e3635e2](https://github.com/AliMD/alwatr-eslib/commit/e3635e2012e5ab5a79622693c5bf7c4639840258)) by @AliMD
|
|
16
|
+
* **logger:** remove desc from incident & accident ([fa38b68](https://github.com/AliMD/alwatr-eslib/commit/fa38b68ce63524f1b53f3ad135450289eff66ae8)) by @AliMD
|
|
17
|
+
|
|
18
|
+
### BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
* **logger:** remove desc from incident & accident
|
|
21
|
+
* **logger:** global Alwatr.registeredList not exist anymore
|
|
22
|
+
|
|
23
|
+
# [1.2.0](https://github.com/AliMD/alwatr-eslib/compare/@alwatr/logger@1.1.5...@alwatr/logger@1.2.0) (2023-10-23)
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **logger:** banner method ([3e3af6d](https://github.com/AliMD/alwatr-eslib/commit/3e3af6d71ccecaaf14ca9d63a8a14c7239afe697)) by @
|
|
28
|
+
|
|
6
29
|
## [1.1.5](https://github.com/AliMD/alwatr-eslib/compare/@alwatr/logger@1.1.4...@alwatr/logger@1.1.5) (2023-09-19)
|
|
7
30
|
|
|
8
31
|
### Bug Fixes
|
|
9
32
|
|
|
10
|
-
|
|
33
|
+
- package repo urls ([466cbe9](https://github.com/AliMD/alwatr-eslib/commit/466cbe9188f24e1a1bc36d879a95b52538a58f16)) by @AliMD
|
|
11
34
|
|
|
12
35
|
## [1.1.4](https://github.com/AliMD/alwatr-eslib/compare/@alwatr/logger@1.1.3...@alwatr/logger@1.1.4) (2023-09-19)
|
|
13
36
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-package.d.ts","sourceRoot":"","sources":["src/define-package.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,aAAa,gBAAiB,MAAM,WAAW,MAAM,SAajE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createLogger } from './logger.js';
|
|
2
|
+
globalThis.Alwatr ?? (globalThis.Alwatr = { packages: {} });
|
|
3
|
+
Alwatr.packages ?? (Alwatr.packages = {});
|
|
4
|
+
const logger = createLogger('logger');
|
|
5
|
+
export const definePackage = (packageName, version) => {
|
|
6
|
+
logger.logMethodArgs?.('define-package', { packageName, version });
|
|
7
|
+
if (packageName in Alwatr.packages) {
|
|
8
|
+
logger.accident?.('define-package', 'duplicate_package_defined', {
|
|
9
|
+
packageName,
|
|
10
|
+
new: version,
|
|
11
|
+
old: Alwatr.packages[packageName],
|
|
12
|
+
});
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
Alwatr.packages[packageName] = version;
|
|
16
|
+
};
|
|
17
|
+
definePackage('logger', '2.x');
|
|
18
|
+
//# sourceMappingURL=define-package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-package.js","sourceRoot":"","sources":["src/define-package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAIzC,UAAU,CAAC,MAAM,KAAjB,UAAU,CAAC,MAAM,GAAK,EAAC,QAAQ,EAAE,EAAE,EAAC,EAAC;AACrC,MAAM,CAAC,QAAQ,KAAf,MAAM,CAAC,QAAQ,GAAK,EAAE,EAAC;AAEvB,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,WAAmB,EAAE,OAAe,EAAE,EAAE;IACpE,MAAM,CAAC,aAAa,EAAE,CAAC,gBAAgB,EAAE,EAAC,WAAW,EAAE,OAAO,EAAC,CAAC,CAAC;IAEjE,IAAI,WAAW,IAAI,MAAM,CAAC,QAAQ,EAAE;QAClC,MAAM,CAAC,QAAQ,EAAE,CAAC,gBAAgB,EAAE,2BAA2B,EAAE;YAC/D,WAAW;YACX,GAAG,EAAE,OAAO;YACZ,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;SAClC,CAAC,CAAC;QACH,OAAO;KACR;IAED,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC;AACzC,CAAC,CAAC;AAEF,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC","sourcesContent":["import {createLogger} from './logger.js';\n\nimport type {} from './type.js';\n\nglobalThis.Alwatr ??= {packages: {}};\nAlwatr.packages ??= {};\n\nconst logger = createLogger('logger');\n\nexport const definePackage = (packageName: string, version: string) => {\n logger.logMethodArgs?.('define-package', {packageName, version});\n\n if (packageName in Alwatr.packages) {\n logger.accident?.('define-package', 'duplicate_package_defined', {\n packageName,\n new: version,\n old: Alwatr.packages[packageName],\n });\n return;\n }\n\n Alwatr.packages[packageName] = version;\n};\n\ndefinePackage('logger', '2.x');\n"]}
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,mBAAmB,WAAW,CAAA"}
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA","sourcesContent":["export * from './logger.js'\nexport * from './define-package.js'\nexport type * from './type.js'\n"]}
|
package/logger.d.ts
CHANGED
package/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAE5C,eAAO,MAAM,SAAS,SAAiC,CAAC;AACxD,eAAO,MAAM,QAAQ,SAEsC,CAAC;AAmD5D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,WAAY,MAAM,wBAAuB,YAoDjE,CAAC"}
|
package/logger.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { globalAlwatr } from './global-alwatr.js';
|
|
2
|
-
export { globalAlwatr };
|
|
3
|
-
globalAlwatr.registeredList.push({
|
|
4
|
-
name: '@alwatr/logger',
|
|
5
|
-
version: _ALWATR_VERSION_,
|
|
6
|
-
});
|
|
7
1
|
export const NODE_MODE = typeof process !== 'undefined';
|
|
8
2
|
export const DEV_MODE = NODE_MODE
|
|
9
3
|
? process.env.ALWATR_DEBUG === '1'
|
|
@@ -75,9 +69,12 @@ export const createLogger = (domain, devMode = DEV_MODE) => {
|
|
|
75
69
|
const requiredItems = {
|
|
76
70
|
devMode,
|
|
77
71
|
domain,
|
|
72
|
+
banner: NODE_MODE
|
|
73
|
+
? console.log.bind(console, `\x1b[1;37;45m\n\n %s${_style.reset}`)
|
|
74
|
+
: console.log.bind(console, '%c%s', 'font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;'),
|
|
78
75
|
accident: NODE_MODE
|
|
79
|
-
? console.warn.bind(console, `${styleScope}⚠️\n%s\x1b[33m.%s() Accident \`%s
|
|
80
|
-
: console.warn.bind(console, '%c%s%c.%s() Accident `%s
|
|
76
|
+
? console.warn.bind(console, `${styleScope}⚠️\n%s\x1b[33m.%s() Accident \`%s\`!${_style.reset}`, domain)
|
|
77
|
+
: console.warn.bind(console, '%c%s%c.%s() Accident `%s`!', styleScope, domain, _style.reset),
|
|
81
78
|
error: NODE_MODE
|
|
82
79
|
? console.error.bind(console, `${styleScope}❌\n%s\x1b[31m.%s() Error \`%s\`${_style.reset}\n`, domain)
|
|
83
80
|
: console.error.bind(console, '%c%s%c.%s() Error `%s`\n', styleScope, domain, _style.reset),
|
|
@@ -95,8 +92,8 @@ export const createLogger = (domain, devMode = DEV_MODE) => {
|
|
|
95
92
|
logMethodFull: console.debug.bind(console, _keySection + '.%s(%o) => %o', styleScope, domain, _style.reset),
|
|
96
93
|
logOther: console.debug.bind(console, _keySection, styleScope, domain, _style.reset),
|
|
97
94
|
incident: NODE_MODE
|
|
98
|
-
? console.log.bind(console, `${styleScope}🚸\n%s${_style.reset}.%s() Incident \`%s
|
|
99
|
-
: console.log.bind(console, '%c%s%c.%s() Incident `%s
|
|
95
|
+
? console.log.bind(console, `${styleScope}🚸\n%s${_style.reset}.%s() Incident \`%s\`!${_style.reset}`, domain)
|
|
96
|
+
: console.log.bind(console, '%c%s%c.%s() Incident `%s`!', styleScope, domain, 'color: orange;'),
|
|
100
97
|
time: (label) => console.time(domain + '.' + label + ' duration time'),
|
|
101
98
|
timeEnd: (label) => console.timeEnd(domain + '.' + label + ' duration time'),
|
|
102
99
|
};
|
package/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AACxD,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS;IAC/B,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,GAAG;IAClC,CAAC,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,GAAG,CAAC;AAE5D;;GAEG;AACH,MAAM,SAAS,GAAG,SAAS;IACzB,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,wBAAwB;IACnE,CAAC,CAAC;QACA,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;KACV,CAAC;AAEJ,IAAI,WAAW,GAAG,CAAC,CAAC;AACpB,MAAM,aAAa,GAAG,GAAW,EAAE;IACjC,MA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E,MAAM,CAAC,KAAK,CAAC;QAEjG,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC;QAEtG,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,eAAe,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC;QAE3G,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC;QAEpF,QAAQ,EAAE,SAAS;YACjB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,SAAS,MAAM,CAAC,KAAK,yBAAyB,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC;YAC9G,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,4BAA4B,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,CAAC;QAEjG,IAAI,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,gBAAgB,CAAC;QAC9E,OAAO,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,gBAAgB,CAAC;KAC5E,CAAC;AACb,CAAC,CAAC","sourcesContent":["import type {AlwatrLogger} from './type.js';\n\nexport const NODE_MODE = typeof process !== 'undefined';\nexport const DEV_MODE = NODE_MODE\n ? process.env.ALWATR_DEBUG === '1'\n : globalThis.localStorage?.getItem('alwatrDebug') === '1';\n\n/**\n * Color list storage for logger.\n */\nconst colorList = NODE_MODE\n ? ['0;36', '0;35', '0;34', '0;33', '0;32'] // red and white omitted\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\nlet _colorIndex = 0;\nconst _getNextColor = (): string => {\n const color = colorList[_colorIndex];\n _colorIndex++;\n if (_colorIndex >= colorList.length) {\n _colorIndex = 0;\n }\n return color;\n};\n\nconst _style = {\n scope: NODE_MODE ? '\\x1b[{{color}}m' : 'color: {{color}};',\n reset: NODE_MODE ? '\\x1b[0m' : 'color: inherit;',\n};\n\nconst _keySection = NODE_MODE ? '%s%s%s' : '%c%s%c';\n\nconst _sanitizeDomain = (domain: string): string => {\n domain = domain.trim();\n const first = domain.charAt(0);\n if (first !== '[' && first !== '{' && first !== '<') {\n domain = '[' + domain + ']';\n }\n return domain;\n};\n\n/**\n * Create a logger function for fancy console debug with custom scope.\n *\n * - **color** is optional and automatically select from internal fancy color list.\n * - **debug** is optional and automatically detect from localStorage `ALWATR_DEBUG` item or `process.env.ALWATR_DEBUG`\n *\n * Example:\n *\n * ```ts\n * import {createLogger} from 'https://esm.run/@alwatr/logger';\n * const logger = createLogger('logger/demo');\n * ```\n */\nexport const createLogger = (domain: string, devMode = DEV_MODE): AlwatrLogger => {\n const color = _getNextColor();\n const styleScope = _style.scope.replaceAll('{{color}}', color);\n domain = _sanitizeDomain(domain);\n\n /**\n * Required logger object, accident, error always reported even when the devMode is false.\n */\n const requiredItems: AlwatrLogger = {\n devMode,\n domain,\n\n banner: NODE_MODE\n ? console.log.bind(console, `\\x1b[1;37;45m\\n\\n %s${_style.reset}`)\n : console.log.bind(console, '%c%s',\n 'font-size: 2rem; background-color: #5858e8; color: #fff; padding: 1rem 4rem; border-radius: 0.5rem;'),\n\n accident: NODE_MODE\n ? console.warn.bind(console, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\`!${_style.reset}`, domain)\n : console.warn.bind(console, '%c%s%c.%s() Accident `%s`!', styleScope, domain, _style.reset),\n\n error: NODE_MODE\n ? console.error.bind(console, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${_style.reset}\\n`, domain)\n : console.error.bind(console, '%c%s%c.%s() Error `%s`\\n', styleScope, domain, _style.reset),\n };\n\n if (!devMode) {\n return requiredItems;\n }\n // else\n return {\n ...requiredItems,\n\n logProperty: console.debug.bind(console, _keySection + '.%s = %o;', styleScope, domain, _style.reset),\n\n logMethod: console.debug.bind(console, _keySection + '.%s();', styleScope, domain, _style.reset),\n\n logModule: console.debug.bind(console, _keySection + '/%s.js;', styleScope, domain, _style.reset),\n\n logMethodArgs: console.debug.bind(console, _keySection + '.%s(%o);', styleScope, domain, _style.reset),\n\n logMethodFull: console.debug.bind(console, _keySection + '.%s(%o) => %o', styleScope, domain, _style.reset),\n\n logOther: console.debug.bind(console, _keySection, styleScope, domain, _style.reset),\n\n incident: NODE_MODE\n ? console.log.bind(console, `${styleScope}🚸\\n%s${_style.reset}.%s() Incident \\`%s\\`!${_style.reset}`, domain)\n : console.log.bind(console, '%c%s%c.%s() Incident `%s`!', styleScope, domain, 'color: orange;'),\n\n time: (label: string) => console.time(domain + '.' + label + ' duration time'),\n timeEnd: (label: string) => console.timeEnd(domain + '.' + label + ' duration time'),\n } as const;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"log",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"esm",
|
|
12
12
|
"alwatr"
|
|
13
13
|
],
|
|
14
|
-
"main": "
|
|
14
|
+
"main": "index.js",
|
|
15
15
|
"type": "module",
|
|
16
|
-
"types": "
|
|
16
|
+
"types": "index.d.ts",
|
|
17
17
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"files": [
|
|
@@ -32,8 +32,7 @@
|
|
|
32
32
|
"url": "https://github.com/AliMD/alwatr-eslib/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@alwatr/type": "^1.1.4",
|
|
36
35
|
"tslib": "^2.6.2"
|
|
37
36
|
},
|
|
38
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "66a820931d638c8e4b465c86bf5c6ad0771d62ad"
|
|
39
38
|
}
|
package/type.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export interface GlobalAlwatr {
|
|
2
|
+
packages: Record<string, string>;
|
|
3
|
+
}
|
|
4
|
+
declare global {
|
|
5
|
+
var Alwatr: GlobalAlwatr;
|
|
6
|
+
}
|
|
1
7
|
export interface AlwatrLogger {
|
|
2
8
|
/**
|
|
3
9
|
* Debug state for current scope base on localStorage `ALWATR_LOG` pattern.
|
|
@@ -72,20 +78,20 @@ export interface AlwatrLogger {
|
|
|
72
78
|
* Example:
|
|
73
79
|
*
|
|
74
80
|
* ```ts
|
|
75
|
-
* logger.incident?.('fetch', 'abort_signal',
|
|
81
|
+
* logger.incident?.('fetch', 'abort_signal', {url: '/test.json'});
|
|
76
82
|
* ```
|
|
77
83
|
*/
|
|
78
|
-
incident?(method: string, code: string,
|
|
84
|
+
incident?(method: string, code: string, ...args: unknown[]): void;
|
|
79
85
|
/**
|
|
80
86
|
* `console.warn` an unexpected accident or error that you handled like warning.
|
|
81
87
|
*
|
|
82
88
|
* Example:
|
|
83
89
|
*
|
|
84
90
|
* ```ts
|
|
85
|
-
* logger.accident('fetch', 'file_not_found',
|
|
91
|
+
* logger.accident('fetch', 'file_not_found', {url: '/test.json'});
|
|
86
92
|
* ```
|
|
87
93
|
*/
|
|
88
|
-
accident(method: string, code: string,
|
|
94
|
+
accident(method: string, code: string, ...args: unknown[]): void;
|
|
89
95
|
/**
|
|
90
96
|
* `console.error` an unexpected error.
|
|
91
97
|
*
|
|
@@ -131,5 +137,15 @@ export interface AlwatrLogger {
|
|
|
131
137
|
* ```
|
|
132
138
|
*/
|
|
133
139
|
timeEnd?(label: string): void;
|
|
140
|
+
/**
|
|
141
|
+
* log big banner
|
|
142
|
+
*
|
|
143
|
+
* Example:
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* logger.banner('Alwatr PWA v2');
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
banner?(message: string): void;
|
|
134
150
|
}
|
|
135
151
|
//# sourceMappingURL=type.d.ts.map
|
package/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;;;;;OAQG;IACH,WAAW,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAErD;;;;;;;;OAQG;IACH,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;;;;;;;;;OAUG;IACH,SAAS,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAEjC;;;;;;;;;;OAUG;IACH,aAAa,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAEpD;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAErE;;;;;;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AAC;IAEjE;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE9D;;;;;;;;OAQG;IACH,QAAQ,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEpC;;;;;;;;OAQG;IACH,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;;;;;;;OAQG;IACH,MAAM,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC"}
|
package/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["export interface AlwatrLogger {\n /**\n * Debug state for current scope base on localStorage `ALWATR_LOG` pattern.\n */\n readonly devMode: boolean;\n\n /**\n * Domain scope defined for this logger.\n */\n readonly domain: string;\n\n /**\n * `console.debug` property change.\n *\n * Example:\n *\n * ```ts\n * logger.logProperty?.('name', 'ali');\n * ```\n */\n logProperty?(property: string, value: unknown): void;\n\n /**\n * `console.debug` module name.\n *\n * Example:\n *\n * ```ts\n * logger.logModule?.('app');\n * ```\n */\n logModule?(name: string): void;\n\n /**\n * `console.debug` function or method calls.\n *\n * Example:\n *\n * ```ts\n * function myMethod () {\n * logger.logMethod?.('myMethod');\n * }\n * ```\n */\n logMethod?(method: string): void;\n\n /**\n * `console.debug` function or method calls with arguments.\n *\n * Example:\n *\n * ```ts\n * function myMethod (a: number, b: number) {\n * logger.logMethodArgs?.('myMethod', {a, b});\n * }\n * ```\n */\n logMethodArgs?(method: string, args: unknown): void;\n\n /**\n * `console.debug` function or method calls with arguments.\n *\n * Example:\n *\n * ```ts\n * function add (a: number, b: number): number {\n * const result = a + b;\n * logger.logMethodFull?.('add', {a, b}, result);\n * return result;\n * }\n * ```\n */\n logMethodFull?(method: string, args: unknown, result: unknown): void;\n\n /**\n * `console.log` an event or expected accident.\n * not warn or error just important information.\n *\n * Example:\n *\n * ```ts\n * logger.incident?.('fetch', 'abort_signal',
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["src/type.ts"],"names":[],"mappings":"","sourcesContent":["export interface GlobalAlwatr {\n packages: Record<string, string>;\n}\n\ndeclare global {\n // eslint-disable-next-line no-var\n var Alwatr: GlobalAlwatr;\n}\n\nexport interface AlwatrLogger {\n /**\n * Debug state for current scope base on localStorage `ALWATR_LOG` pattern.\n */\n readonly devMode: boolean;\n\n /**\n * Domain scope defined for this logger.\n */\n readonly domain: string;\n\n /**\n * `console.debug` property change.\n *\n * Example:\n *\n * ```ts\n * logger.logProperty?.('name', 'ali');\n * ```\n */\n logProperty?(property: string, value: unknown): void;\n\n /**\n * `console.debug` module name.\n *\n * Example:\n *\n * ```ts\n * logger.logModule?.('app');\n * ```\n */\n logModule?(name: string): void;\n\n /**\n * `console.debug` function or method calls.\n *\n * Example:\n *\n * ```ts\n * function myMethod () {\n * logger.logMethod?.('myMethod');\n * }\n * ```\n */\n logMethod?(method: string): void;\n\n /**\n * `console.debug` function or method calls with arguments.\n *\n * Example:\n *\n * ```ts\n * function myMethod (a: number, b: number) {\n * logger.logMethodArgs?.('myMethod', {a, b});\n * }\n * ```\n */\n logMethodArgs?(method: string, args: unknown): void;\n\n /**\n * `console.debug` function or method calls with arguments.\n *\n * Example:\n *\n * ```ts\n * function add (a: number, b: number): number {\n * const result = a + b;\n * logger.logMethodFull?.('add', {a, b}, result);\n * return result;\n * }\n * ```\n */\n logMethodFull?(method: string, args: unknown, result: unknown): void;\n\n /**\n * `console.log` an event or expected accident.\n * not warn or error just important information.\n *\n * Example:\n *\n * ```ts\n * logger.incident?.('fetch', 'abort_signal', {url: '/test.json'});\n * ```\n */\n incident?(method: string, code: string, ...args: unknown[]): void;\n\n /**\n * `console.warn` an unexpected accident or error that you handled like warning.\n *\n * Example:\n *\n * ```ts\n * logger.accident('fetch', 'file_not_found', {url: '/test.json'});\n * ```\n */\n accident(method: string, code: string, ...args: unknown[]): void;\n\n /**\n * `console.error` an unexpected error.\n *\n * Example:\n *\n * ```ts\n * try {\n * ...\n * }\n * catch (err) {\n * logger.error('myMethod', 'error_code', err, {a: 1, b: 2});\n * }\n * ```\n */\n error(method: string, code: string, ...args: unknown[]): void;\n\n /**\n * Simple `console.debug` with styled scope.\n *\n * Example:\n *\n * ```ts\n * logger.logOther?.('foo:', 'bar', {a: 1});\n * ```\n */\n logOther?(...args: unknown[]): void;\n\n /**\n * Simple `console.time` with scope.\n *\n * Example:\n *\n * ```ts\n * logger.time?.('foo');\n * ```\n */\n time?(label: string): void;\n\n /**\n * Simple `console.timeEnd` with scope.\n *\n * Example:\n *\n * ```ts\n * logger.timeEnd?.('foo');\n * ```\n */\n timeEnd?(label: string): void;\n\n /**\n * log big banner\n *\n * Example:\n *\n * ```ts\n * logger.banner('Alwatr PWA v2');\n * ```\n */\n banner?(message: string): void;\n}\n"]}
|
package/global-alwatr.d.ts
DELETED
package/global-alwatr.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global-alwatr.d.ts","sourceRoot":"","sources":["src/global-alwatr.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,YAAY,+CAAS,CAAC"}
|
package/global-alwatr.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
if (globalThis.Alwatr == null) {
|
|
2
|
-
globalThis.Alwatr = {
|
|
3
|
-
registeredList: [],
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
try {
|
|
7
|
-
_ALWATR_VERSION_;
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
globalThis._ALWATR_VERSION_ = 'ERROR';
|
|
11
|
-
console.warn('!! SCRIPTS LOADED OUTSIDE OF ALWATR BUILD ENVIRONMENT !!');
|
|
12
|
-
}
|
|
13
|
-
if (Alwatr.registeredList == null) {
|
|
14
|
-
Alwatr.registeredList = [];
|
|
15
|
-
}
|
|
16
|
-
export const globalAlwatr = Alwatr;
|
|
17
|
-
//# sourceMappingURL=global-alwatr.js.map
|
package/global-alwatr.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global-alwatr.js","sourceRoot":"","sources":["src/global-alwatr.ts"],"names":[],"mappings":"AAEA,IAAI,UAAU,CAAC,MAAM,IAAI,IAAI,EAAE;IAC7B,UAAU,CAAC,MAAM,GAAG;QAClB,cAAc,EAAE,EAAE;KACnB,CAAC;CACH;AAED,IAAI;IACF,gBAAgB,CAAC;CAClB;AACD,MAAM;IACJ,UAAU,CAAC,gBAAgB,GAAG,OAAO,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,0DAA0D,CAAC,CAAC;CAC1E;AAED,IAAI,MAAM,CAAC,cAAc,IAAI,IAAI,EAAE;IACjC,MAAM,CAAC,cAAc,GAAG,EAAE,CAAC;CAC5B;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC","sourcesContent":["import type {} from '@alwatr/type/global.js';\n\nif (globalThis.Alwatr == null) {\n globalThis.Alwatr = {\n registeredList: [],\n };\n}\n\ntry {\n _ALWATR_VERSION_;\n}\ncatch {\n globalThis._ALWATR_VERSION_ = 'ERROR';\n console.warn('!! SCRIPTS LOADED OUTSIDE OF ALWATR BUILD ENVIRONMENT !!');\n}\n\nif (Alwatr.registeredList == null) {\n Alwatr.registeredList = [];\n}\n\nexport const globalAlwatr = Alwatr;\n"]}
|