@qqi/log 1.0.0 → 1.1.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/cjs/setType.js DELETED
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- const typeList = [
4
- false,
5
- true,
6
- 'all',
7
- 'info',
8
- 'error',
9
- 'warn',
10
- ];
11
- /**
12
- * 设置 type 的类型
13
- */
14
- function setType(type) {
15
- if (typeList.includes(type))
16
- return type;
17
- return false;
18
- }
19
-
20
- exports.setType = setType;
21
- exports.typeList = typeList;
package/es/blankCall.js DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- *
3
- * 空函数
4
- *
5
- */
6
- function blankCall(...str) {
7
- }
8
-
9
- export { blankCall };
package/es/managePrint.js DELETED
@@ -1,51 +0,0 @@
1
- import { isUndefined } from 'a-type-of-js';
2
- import { notSupport } from './notSupport.js';
3
- import { platform } from './platform.js';
4
- import { blankCall } from './blankCall.js';
5
- import { printError } from './printError.js';
6
- import { printWarn } from './printWarn.js';
7
- import { printInfo } from './printInfo.js';
8
- import { typeList } from './setType.js';
9
-
10
- /** 管理是否打印 */
11
- function managePrint(type, privateFunc, name) {
12
- if (platform === 'node') {
13
- const dev = globalThis?.process.env[name.toUpperCase().concat('_DEV')] ||
14
- globalThis?.process.env[name.toLowerCase().concat('_dev')];
15
- /// 当前禁止使用打印
16
- /// node 环境未配置 NAME_DEV 环境变量
17
- /// 显式配置 NAME_DEV 环境变量为 false
18
- if (type === false || isUndefined(dev) || dev === 'false') {
19
- return Reflect.apply(notSupport, privateFunc, []);
20
- }
21
- /// 将显示配置环境变量的值给 type
22
- if ([...typeList, 'true', 'false'].includes(dev)) {
23
- type = dev === 'true' ? 'all' : dev;
24
- }
25
- privateFunc.info = ['all', 'info', true].includes(type)
26
- ? printInfo
27
- : blankCall;
28
- privateFunc.error = ['all', 'error', true].includes(type)
29
- ? printError
30
- : blankCall;
31
- privateFunc.warn = ['all', 'warn', true].includes(type)
32
- ? printWarn
33
- : blankCall;
34
- }
35
- // 在 非 node 环境始终执行,搭配 @qqi/babel-plugin-remove-dog-calls 使用
36
- else {
37
- if (type === false)
38
- return Reflect.apply(notSupport, privateFunc, []);
39
- privateFunc.info = ['all', 'info', true].includes(type)
40
- ? printInfo
41
- : blankCall;
42
- privateFunc.error = ['all', 'error', true].includes(type)
43
- ? printError
44
- : blankCall;
45
- privateFunc.warn = ['all', 'warn', true].includes(type)
46
- ? printWarn
47
- : blankCall;
48
- }
49
- }
50
-
51
- export { managePrint };
package/es/notSupport.js DELETED
@@ -1,12 +0,0 @@
1
- import { blankCall } from './blankCall.js';
2
-
3
- /**
4
- * 当前环境不支持
5
- *
6
- * 三个方法都是空方法
7
- */
8
- function notSupport() {
9
- this.error = this.info = this.warn = blankCall;
10
- }
11
-
12
- export { notSupport };
package/es/parseError.js DELETED
@@ -1,40 +0,0 @@
1
- import { pen } from 'color-pen';
2
-
3
- /**
4
- *
5
- * 解析 error
6
- *
7
- */
8
- function parseError(type) {
9
- try {
10
- throw new Error();
11
- }
12
- catch (error) {
13
- const parseErrorResult = (error.stack?.split('\n') || []).map(item => {
14
- const reg = /at\s(.*)\s\((.*):(\d*):(\d*)\)/;
15
- const res = reg.exec(item);
16
- if (res) {
17
- return {
18
- name: res[1],
19
- path: res[2],
20
- line: res[3],
21
- column: res[4],
22
- };
23
- }
24
- return {
25
- name: '',
26
- };
27
- });
28
- const result = parseErrorResult.filter(e => e.name !== '' && e.path !== undefined);
29
- const res = result[3] ?? result[2] ?? result[1] ?? result[0];
30
- const startStr = ` ${type === 'info' ? '💡' : type === 'error' ? '❌' : '⚠️ '} ${new Date().toLocaleString()} `;
31
- const printStartPenStr = (type === 'info'
32
- ? pen.bgCyan.brightWhite
33
- : type === 'error'
34
- ? pen.bgBlack.red
35
- : pen.bgBrightYellow.brightGreen)(startStr);
36
- console.log(`${printStartPenStr} ${res?.name ?? ''} ${res?.line?.concat(' 行')} ${res?.column?.concat(' 列')}`);
37
- }
38
- }
39
-
40
- export { parseError };
package/es/platform.js DELETED
@@ -1,5 +0,0 @@
1
- import { isNode } from 'a-js-tools';
2
-
3
- const platform = isNode() ? 'node' : 'browser';
4
-
5
- export { platform };
package/es/printError.js DELETED
@@ -1,13 +0,0 @@
1
- import { parseError } from './parseError.js';
2
-
3
- /**
4
- *
5
- * 打印 error 信息
6
- *
7
- */
8
- function printError(...str) {
9
- parseError('error');
10
- console.error(...str);
11
- }
12
-
13
- export { printError };
package/es/printInfo.js DELETED
@@ -1,13 +0,0 @@
1
- import { parseError } from './parseError.js';
2
-
3
- /**
4
- *
5
- * 打印 info 消息
6
- *
7
- */
8
- function printInfo(...str) {
9
- parseError('info');
10
- console.info(...str);
11
- }
12
-
13
- export { printInfo };
package/es/printWarn.js DELETED
@@ -1,13 +0,0 @@
1
- import { parseError } from './parseError.js';
2
-
3
- /**
4
- *
5
- * 打印 warn 信息
6
- *
7
- */
8
- function printWarn(...str) {
9
- parseError('warn');
10
- console.warn(...str);
11
- }
12
-
13
- export { printWarn };
package/es/setType.js DELETED
@@ -1,18 +0,0 @@
1
- const typeList = [
2
- false,
3
- true,
4
- 'all',
5
- 'info',
6
- 'error',
7
- 'warn',
8
- ];
9
- /**
10
- * 设置 type 的类型
11
- */
12
- function setType(type) {
13
- if (typeList.includes(type))
14
- return type;
15
- return false;
16
- }
17
-
18
- export { setType, typeList };
@@ -1,6 +0,0 @@
1
- /**
2
- *
3
- * 空函数
4
- *
5
- */
6
- export declare function blankCall(...str: unknown[]): void;
@@ -1,3 +0,0 @@
1
- import { DevLogType, PrivateFunc } from './type';
2
- /** 管理是否打印 */
3
- export declare function managePrint(type: DevLogType, privateFunc: PrivateFunc, name: string): void;
@@ -1,7 +0,0 @@
1
- import { PrivateFunc } from './type';
2
- /**
3
- * 当前环境不支持
4
- *
5
- * 三个方法都是空方法
6
- */
7
- export declare function notSupport(this: PrivateFunc): void;
@@ -1,7 +0,0 @@
1
- import { DevLogType } from './type';
2
- /**
3
- *
4
- * 解析 error
5
- *
6
- */
7
- export declare function parseError(type: DevLogType): void;
@@ -1 +0,0 @@
1
- export declare const platform: string;
@@ -1,6 +0,0 @@
1
- /**
2
- *
3
- * 打印 error 信息
4
- *
5
- */
6
- export declare function printError(...str: unknown[]): void;
@@ -1,6 +0,0 @@
1
- /**
2
- *
3
- * 打印 info 消息
4
- *
5
- */
6
- export declare function printInfo(...str: unknown[]): void;
@@ -1,6 +0,0 @@
1
- /**
2
- *
3
- * 打印 warn 信息
4
- *
5
- */
6
- export declare function printWarn(...str: unknown[]): void;
@@ -1,6 +0,0 @@
1
- import { DevLogType } from './type';
2
- export declare const typeList: DevLogType[];
3
- /**
4
- * 设置 type 的类型
5
- */
6
- export declare function setType(type: DevLogType): DevLogType;