@alwatr/logger 0.29.0 → 0.30.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.30.0](https://github.com/AliMD/alwatr/compare/v0.29.0...v0.30.0) (2023-03-06)
7
+
8
+ ### Features
9
+
10
+ - **logger:** export isBrowser ([5b5be8b](https://github.com/AliMD/alwatr/commit/5b5be8b2312ca67f186d1614506423f1fdb90877))
11
+
6
12
  # [0.29.0](https://github.com/AliMD/alwatr/compare/v0.28.0...v0.29.0) (2023-02-10)
7
13
 
8
14
  **Note:** Version bump only for package @alwatr/logger
package/logger.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { globalAlwatr } from './global-alwatr.js';
2
2
  import type { AlwatrLogger } from './type.js';
3
3
  export { type AlwatrLogger, globalAlwatr };
4
+ export declare const isBrowser: boolean;
4
5
  export declare const style: {
5
6
  scope: string;
6
7
  reset: string;
package/logger.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAC,KAAK,YAAY,EAAE,YAAY,EAAC,CAAC;AA+EzC,eAAO,MAAM,KAAK;;;CAGjB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,UAAU,MAAM,GAAG,IAAI,UAAU,OAAO,KAAG,YA+DpF,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAC,KAAK,YAAY,EAAE,YAAY,EAAC,CAAC;AAEzC,eAAO,MAAM,SAAS,SAAiC,CAAC;AA6ExD,eAAO,MAAM,KAAK;;;CAGjB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,UAAU,MAAM,GAAG,IAAI,UAAU,OAAO,KAAG,YA+DpF,CAAC"}
package/logger.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var _a, _b, _c, _d;
2
2
  import { globalAlwatr } from './global-alwatr.js';
3
3
  export { globalAlwatr };
4
- const isBrowser = typeof process === 'undefined';
4
+ export const isBrowser = typeof process === 'undefined';
5
5
  globalAlwatr.registeredList.push({
6
6
  name: '@alwatr/logger',
7
7
  version: _ALWATR_VERSION_,
package/logger.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["src/logger.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAoB,YAAY,EAAC,CAAC;AAEzC,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAEjD,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC;IAC/B,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,gBAAgB;CAC1B,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,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AAO,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 {globalAlwatr} from './global-alwatr.js';\n\nimport type {AlwatrLogger} from './type.js';\n\nexport {type AlwatrLogger, globalAlwatr};\n\nconst isBrowser = typeof process === 'undefined';\n\nglobalAlwatr.registeredList.push({\n name: '@alwatr/logger',\n version: _ALWATR_VERSION_,\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":";AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAoB,YAAY,EAAC,CAAC;AAEzC,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAExD,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC;IAC/B,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,gBAAgB;CAC1B,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;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AAO,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 {globalAlwatr} from './global-alwatr.js';\n\nimport type {AlwatrLogger} from './type.js';\n\nexport {type AlwatrLogger, globalAlwatr};\n\nexport const isBrowser = typeof process === 'undefined';\n\nglobalAlwatr.registeredList.push({\n name: '@alwatr/logger',\n version: _ALWATR_VERSION_,\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.29.0",
3
+ "version": "0.30.0",
4
4
  "description": "Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.",
5
5
  "keywords": [
6
6
  "log",
@@ -32,8 +32,8 @@
32
32
  "url": "https://github.com/AliMD/alwatr/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@alwatr/type": "^0.29.0",
35
+ "@alwatr/type": "^0.30.0",
36
36
  "tslib": "^2.5.0"
37
37
  },
38
- "gitHead": "801487f183f8afd8cba25e0fec5d508c0b4fe809"
38
+ "gitHead": "36f55780ccdcb1acc07400b0cdb3fe7b0df56cca"
39
39
  }