@alwatr/logger 0.26.0 → 0.27.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 CHANGED
@@ -3,6 +3,12 @@
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
+ # [0.27.0](https://github.com/AliMD/alwatr/compare/v0.26.0...v0.27.0) (2022-12-29)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **logger:** version ([2295fee](https://github.com/AliMD/alwatr/commit/2295fee74e8eebd9db399129de31f2b0d6d6b168))
11
+
6
12
  # [0.26.0](https://github.com/AliMD/alwatr/compare/v0.25.0...v0.26.0) (2022-12-22)
7
13
 
8
14
  ### Bug Fixes
package/logger.js CHANGED
@@ -4,7 +4,7 @@ const isBrowser = typeof process === 'undefined';
4
4
  * Define `globalThis.Alwatr.registeredList`
5
5
  */
6
6
  export const alwatrRegisteredList = ((_a = globalThis.Alwatr) === null || _a === void 0 ? void 0 : _a.registeredList) || [];
7
- (_b = globalThis.Alwatr) !== null && _b !== void 0 ? _b : (globalThis.Alwatr = { version: '0.25.0', registeredList: alwatrRegisteredList });
7
+ (_b = globalThis.Alwatr) !== null && _b !== void 0 ? _b : (globalThis.Alwatr = { version: '0.26.0', registeredList: alwatrRegisteredList });
8
8
  alwatrRegisteredList.push({
9
9
  name: '@alwatr/logger',
10
10
  version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.
package/logger.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":";AAGA,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAA,MAAA,UAAU,CAAC,MAAM,0CAAE,cAAc,KAAI,EAAE,CAAC;AAC5E,MAAA,UAAU,CAAC,MAAM,oCAAj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AE,KAAK;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC;KACH;IAED,uCAAuC;IACvC,OAAO;QACL,GAAG,aAAa;QAEhB,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;QAElG,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;QAE7F,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;QAEnG,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;QAExG,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;QAEjF,QAAQ,EAAE,SAAS;YACjB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,+BAA+B,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAgB,CAAC;YACjG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,SAAS,KAAK,CAAC,KAAK,4BAA4B,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC;KACjH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {AlwatrLogger} from './type.js';\nexport {AlwatrLogger};\n\nconst isBrowser = typeof process === 'undefined';\n\n/**\n * Define `globalThis.Alwatr.registeredList`\n */\nexport const alwatrRegisteredList = globalThis.Alwatr?.registeredList || [];\nglobalThis.Alwatr ??= {version: '0.25.0', registeredList: alwatrRegisteredList};\n\nalwatrRegisteredList.push({\n name: '@alwatr/logger',\n version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.\n});\n\n/**\n * Color list storage for logger.\n */\nlet colorIndex = 0;\nconst colorList = isBrowser\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 : ['0;36', '0;35', '0;34', '0;33', '0;32']; // red and white omitted\n\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 debugString = isBrowser\n ? globalThis.localStorage?.getItem('ALWATR_DEBUG')?.trim()\n : process?.env?.ALWATR_DEBUG?.trim();\n\nconst getDebugState = (scope: string): boolean => {\n if (debugString == null && isBrowser === false && process.env.NODE_ENV !== 'production') {\n return true;\n }\n\n // prettier-ignore\n if (\n debugString == null ||\n debugString == ''\n ) {\n return false;\n }\n\n // prettier-ignore\n if (\n debugString === scope ||\n debugString === '*' ||\n (\n debugString.indexOf('*') === 0 && // starts with `*` for example: `*alwatr*`\n scope.indexOf(debugString.replaceAll('*', '')) !== -1\n ) ||\n (\n debugString.indexOf('*') === debugString.length - 1 && // ends with `*` for example: `alwatr/*`\n scope.indexOf(debugString.replaceAll('*', '')) === 0\n )\n ) {\n return true;\n }\n\n // else\n return false;\n};\n\nexport const style = {\n scope: isBrowser ? 'color: {{color}};' : '\\x1b[{{color}}m',\n reset: isBrowser ? 'color: inherit;' : '\\x1b[0m',\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 = (scope: string, color?: string | null, debug?: boolean): AlwatrLogger => {\n scope = scope.trim();\n color ??= getNextColor();\n debug ??= getDebugState(scope);\n\n const first = scope.charAt(0);\n if (first !== '[' && first !== '{' && first !== '(' && first !== '<') {\n scope = '[' + scope + ']';\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const empty = (): void => {};\n\n const keySection = isBrowser ? '%c%s%c' : '%s%s%s';\n const styleScope = style.scope.replaceAll('{{color}}', color);\n\n /**\n * Required logger object, accident, error always reported even when the debug is false.\n */\n const requiredItems = {\n debug,\n color,\n scope,\n\n accident: isBrowser\n ? console.warn.bind(console, '%c%s%c.%s() Accident `%s` %s!', styleScope, scope, style.reset)\n : console.warn.bind(console, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\` %s!${style.reset}`, scope),\n\n error: isBrowser\n ? console.error.bind(console, '%c%s%c.%s() Error `%s`\\n', styleScope, scope, style.reset)\n : console.error.bind(console, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${style.reset}\\n`, scope),\n };\n\n if (!debug) {\n return {\n ...requiredItems,\n logProperty: empty,\n logMethod: empty,\n logMethodArgs: empty,\n logMethodFull: empty,\n logOther: empty,\n incident: empty,\n };\n }\n\n // else if debug is true for this scope\n return {\n ...requiredItems,\n\n logProperty: console.debug.bind(console, keySection + '.%s = %o;', styleScope, scope, style.reset),\n\n logMethod: console.debug.bind(console, keySection + '.%s();', styleScope, scope, style.reset),\n\n logMethodArgs: console.debug.bind(console, keySection + '.%s(%o);', styleScope, scope, style.reset),\n\n logMethodFull: console.debug.bind(console, keySection + '.%s(%o) => %o', styleScope, scope, style.reset),\n\n logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),\n\n incident: isBrowser\n ? console.log.bind(console, '%c%s%c.%s() Incident `%s` %s!', styleScope, scope, 'color: orange;')\n : console.log.bind(console, `${styleScope}🚸\\n%s${style.reset}.%s() Incident \\`%s\\` %s!${style.reset}`, scope),\n };\n};\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":";AAGA,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAA,MAAA,UAAU,CAAC,MAAM,0CAAE,cAAc,KAAI,EAAE,CAAC;AAC5E,MAAA,UAAU,CAAC,MAAM,oCAAjB,UAAU,CAAC,MAAM,GAAK,EAAC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,oBAAoB,EAAC,EAAC;AAEhF,oBAAoB,CAAC,IAAI,CAAC;IACxB,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,oBAAoB,EAAE,mDAAmD;CACnF,CAAC,CAAC;AAEH;;GAEG;AACH,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,MAAM,SAAS,GAAG,SAAS;IACzB,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;IACD,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,wBAAwB;AAEtE,MAAM,YAAY,GAAG,GAAW,EAAE;IAChC,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IACpC,UAAU,EAAE,CAAC;IACb,IAAI,UAAU,IAAI,SAAS,CAAC,MAAM,EAAE;QAClC,UAAU,GAAG,CAAC,CAAC;KAChB;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,SAAS;IAC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AAI,CAAC,OAAO,EAAE,+BAA+B,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAgB,CAAC;YACjG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,SAAS,KAAK,CAAC,KAAK,4BAA4B,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC;KACjH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {AlwatrLogger} from './type.js';\nexport {AlwatrLogger};\n\nconst isBrowser = typeof process === 'undefined';\n\n/**\n * Define `globalThis.Alwatr.registeredList`\n */\nexport const alwatrRegisteredList = globalThis.Alwatr?.registeredList || [];\nglobalThis.Alwatr ??= {version: '0.26.0', registeredList: alwatrRegisteredList};\n\nalwatrRegisteredList.push({\n name: '@alwatr/logger',\n version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.\n});\n\n/**\n * Color list storage for logger.\n */\nlet colorIndex = 0;\nconst colorList = isBrowser\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 : ['0;36', '0;35', '0;34', '0;33', '0;32']; // red and white omitted\n\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 debugString = isBrowser\n ? globalThis.localStorage?.getItem('ALWATR_DEBUG')?.trim()\n : process?.env?.ALWATR_DEBUG?.trim();\n\nconst getDebugState = (scope: string): boolean => {\n if (debugString == null && isBrowser === false && process.env.NODE_ENV !== 'production') {\n return true;\n }\n\n // prettier-ignore\n if (\n debugString == null ||\n debugString == ''\n ) {\n return false;\n }\n\n // prettier-ignore\n if (\n debugString === scope ||\n debugString === '*' ||\n (\n debugString.indexOf('*') === 0 && // starts with `*` for example: `*alwatr*`\n scope.indexOf(debugString.replaceAll('*', '')) !== -1\n ) ||\n (\n debugString.indexOf('*') === debugString.length - 1 && // ends with `*` for example: `alwatr/*`\n scope.indexOf(debugString.replaceAll('*', '')) === 0\n )\n ) {\n return true;\n }\n\n // else\n return false;\n};\n\nexport const style = {\n scope: isBrowser ? 'color: {{color}};' : '\\x1b[{{color}}m',\n reset: isBrowser ? 'color: inherit;' : '\\x1b[0m',\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 = (scope: string, color?: string | null, debug?: boolean): AlwatrLogger => {\n scope = scope.trim();\n color ??= getNextColor();\n debug ??= getDebugState(scope);\n\n const first = scope.charAt(0);\n if (first !== '[' && first !== '{' && first !== '(' && first !== '<') {\n scope = '[' + scope + ']';\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const empty = (): void => {};\n\n const keySection = isBrowser ? '%c%s%c' : '%s%s%s';\n const styleScope = style.scope.replaceAll('{{color}}', color);\n\n /**\n * Required logger object, accident, error always reported even when the debug is false.\n */\n const requiredItems = {\n debug,\n color,\n scope,\n\n accident: isBrowser\n ? console.warn.bind(console, '%c%s%c.%s() Accident `%s` %s!', styleScope, scope, style.reset)\n : console.warn.bind(console, `${styleScope}⚠️\\n%s\\x1b[33m.%s() Accident \\`%s\\` %s!${style.reset}`, scope),\n\n error: isBrowser\n ? console.error.bind(console, '%c%s%c.%s() Error `%s`\\n', styleScope, scope, style.reset)\n : console.error.bind(console, `${styleScope}❌\\n%s\\x1b[31m.%s() Error \\`%s\\`${style.reset}\\n`, scope),\n };\n\n if (!debug) {\n return {\n ...requiredItems,\n logProperty: empty,\n logMethod: empty,\n logMethodArgs: empty,\n logMethodFull: empty,\n logOther: empty,\n incident: empty,\n };\n }\n\n // else if debug is true for this scope\n return {\n ...requiredItems,\n\n logProperty: console.debug.bind(console, keySection + '.%s = %o;', styleScope, scope, style.reset),\n\n logMethod: console.debug.bind(console, keySection + '.%s();', styleScope, scope, style.reset),\n\n logMethodArgs: console.debug.bind(console, keySection + '.%s(%o);', styleScope, scope, style.reset),\n\n logMethodFull: console.debug.bind(console, keySection + '.%s(%o) => %o', styleScope, scope, style.reset),\n\n logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),\n\n incident: isBrowser\n ? console.log.bind(console, '%c%s%c.%s() Incident `%s` %s!', styleScope, scope, 'color: orange;')\n : console.log.bind(console, `${styleScope}🚸\\n%s${style.reset}.%s() Incident \\`%s\\` %s!${style.reset}`, scope),\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwatr/logger",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
5
5
  "keywords": [
6
6
  "log",
@@ -34,5 +34,5 @@
34
34
  "dependencies": {
35
35
  "tslib": "~2.4.1"
36
36
  },
37
- "gitHead": "95b0562adb46ab0266d860251e16aa0c4e9b4c09"
37
+ "gitHead": "f6612d969fe49af71ab27e75fa54601071953141"
38
38
  }