@anjianshi/utils 1.0.3 → 1.0.5

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/init-dayjs.js CHANGED
@@ -1,7 +1,8 @@
1
- import { extend, locale } from 'dayjs';
1
+ import dayjs from 'dayjs';
2
2
  import objectSupport from 'dayjs/plugin/objectSupport.js';
3
3
  import 'dayjs/locale/zh-cn.js';
4
4
  export function initDayJs() {
5
- extend(objectSupport);
6
- locale('zh-cn');
5
+ // dayjs 的类型标记错误,这两个方法只能通过 dayjs 对象访问,并不能直接引入
6
+ dayjs.extend(objectSupport); // eslint-disable-line import/no-named-as-default-member
7
+ dayjs.locale('zh-cn'); // eslint-disable-line import/no-named-as-default-member
7
8
  }
@@ -2,4 +2,4 @@ import type { Debug } from 'debug';
2
2
  /**
3
3
  * 适配 debug package
4
4
  */
5
- export declare function adaptDebugLib(debugLib: Debug, enable?: string): void;
5
+ export declare function adaptDebugLib(debugLib: Debug, enable?: string, logger?: import("./index.js").Logger): void;
package/logging/adapt.js CHANGED
@@ -2,7 +2,7 @@ import { getLogger } from './index.js';
2
2
  /**
3
3
  * 适配 debug package
4
4
  */
5
- export function adaptDebugLib(debugLib, enable = '') {
5
+ export function adaptDebugLib(debugLib, enable = '', logger = getLogger('3rd-library')) {
6
6
  // 不在 localStorage 里记录 debugLib enable 状态,
7
7
  // 以解决 web worker 里读不到 localStorage 而无法启用 debugLib 日志的问题
8
8
  const emulate = {
@@ -30,7 +30,6 @@ export function adaptDebugLib(debugLib, enable = '') {
30
30
  };
31
31
  Object.assign(debugLib, emulate);
32
32
  // 将 debugLib 日志转发给 logger
33
- const logger = getLogger('3rd-library');
34
33
  debugLib.log = logger.debug.bind(logger);
35
34
  if (enable) {
36
35
  debugLib.enable(enable);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anjianshi/utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Common JavaScript Utils",
5
5
  "homepage": "https://github.com/anjianshi/js-utils",
6
6
  "bugs": {
package/src/init-dayjs.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { extend, locale } from 'dayjs'
1
+ import dayjs from 'dayjs'
2
2
  import objectSupport from 'dayjs/plugin/objectSupport.js'
3
3
  import 'dayjs/locale/zh-cn.js'
4
4
 
5
5
  export function initDayJs() {
6
- extend(objectSupport)
7
- locale('zh-cn')
6
+ // dayjs 的类型标记错误,这两个方法只能通过 dayjs 对象访问,并不能直接引入
7
+ dayjs.extend(objectSupport) // eslint-disable-line import/no-named-as-default-member
8
+ dayjs.locale('zh-cn') // eslint-disable-line import/no-named-as-default-member
8
9
  }
@@ -4,7 +4,7 @@ import { getLogger } from './index.js'
4
4
  /**
5
5
  * 适配 debug package
6
6
  */
7
- export function adaptDebugLib(debugLib: Debug, enable = '') {
7
+ export function adaptDebugLib(debugLib: Debug, enable = '', logger = getLogger('3rd-library')) {
8
8
  // 不在 localStorage 里记录 debugLib enable 状态,
9
9
  // 以解决 web worker 里读不到 localStorage 而无法启用 debugLib 日志的问题
10
10
  const emulate = {
@@ -31,7 +31,6 @@ export function adaptDebugLib(debugLib: Debug, enable = '') {
31
31
  Object.assign(debugLib, emulate)
32
32
 
33
33
  // 将 debugLib 日志转发给 logger
34
- const logger = getLogger('3rd-library')
35
34
  debugLib.log = logger.debug.bind(logger)
36
35
 
37
36
  if (enable) {
@@ -14,7 +14,7 @@ export enum LogLevel {
14
14
  }
15
15
 
16
16
  export interface LogInfo {
17
- logger: string // logger name;有多级 logger 的情况下,这是最初的 logger 名称
17
+ logger: string // 生成此条日志的 logger name;有多级 logger 的情况下,这是最初的 logger 名称
18
18
  level: LogLevel
19
19
  time: Dayjs
20
20
  args: unknown[] // log content