@qqi/log 0.1.1 → 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/LICENSE +2 -2
- package/README.md +11 -1
- package/cjs/index.js +185 -0
- package/cjs/util.js +87 -0
- package/es/eslint.config.d.ts +1222 -0
- package/es/index.js +182 -0
- package/es/rollup.config.d.ts +17 -0
- package/es/rollup.config.eg.d.ts +14 -0
- package/{src → es/src}/index.d.ts +4 -0
- package/{src → es/src}/type.d.ts +11 -9
- package/es/src/util.d.ts +35 -0
- package/es/util.js +81 -0
- package/package.json +38 -42
- package/index.cjs +0 -7
- package/index.d.ts +0 -2
- package/index.mjs +0 -1
- package/src/blankCall.cjs +0 -11
- package/src/blankCall.d.ts +0 -6
- package/src/blankCall.mjs +0 -9
- package/src/index.cjs +0 -106
- package/src/index.mjs +0 -104
- package/src/managePrint.cjs +0 -53
- package/src/managePrint.d.ts +0 -3
- package/src/managePrint.mjs +0 -51
- package/src/notSupport.cjs +0 -14
- package/src/notSupport.d.ts +0 -7
- package/src/notSupport.mjs +0 -12
- package/src/parseError.cjs +0 -42
- package/src/parseError.d.ts +0 -7
- package/src/parseError.mjs +0 -40
- package/src/platform.cjs +0 -7
- package/src/platform.d.ts +0 -1
- package/src/platform.mjs +0 -5
- package/src/printError.cjs +0 -15
- package/src/printError.d.ts +0 -6
- package/src/printError.mjs +0 -13
- package/src/printInfo.cjs +0 -15
- package/src/printInfo.d.ts +0 -6
- package/src/printInfo.mjs +0 -13
- package/src/printWarn.cjs +0 -15
- package/src/printWarn.d.ts +0 -6
- package/src/printWarn.mjs +0 -13
- package/src/setType.cjs +0 -21
- package/src/setType.d.ts +0 -6
- package/src/setType.mjs +0 -18
package/src/index.mjs
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { createConstructor, getRandomString } from 'a-js-tools';
|
|
2
|
-
import { setType } from './setType.mjs';
|
|
3
|
-
import { blankCall } from './blankCall.mjs';
|
|
4
|
-
import { managePrint } from './managePrint.mjs';
|
|
5
|
-
import { isUndefined, isBoolean, isString } from 'a-type-of-js';
|
|
6
|
-
import { platform } from './platform.mjs';
|
|
7
|
-
import { esc } from '@color-pen/static';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* 创建 dev log 工厂函数
|
|
12
|
-
*
|
|
13
|
-
* @param options - 配置项
|
|
14
|
-
* @returns - dev log 工厂函数
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
function Dog(options) {
|
|
19
|
-
if (isUndefined(options))
|
|
20
|
-
options = {
|
|
21
|
-
name: getRandomString(10),
|
|
22
|
-
type: false,
|
|
23
|
-
};
|
|
24
|
-
if (isBoolean(options))
|
|
25
|
-
options = {
|
|
26
|
-
name: getRandomString(10),
|
|
27
|
-
type: options,
|
|
28
|
-
};
|
|
29
|
-
if (isString(options))
|
|
30
|
-
options = {
|
|
31
|
-
name: options,
|
|
32
|
-
type: false,
|
|
33
|
-
};
|
|
34
|
-
let { name = '', type = false } = options;
|
|
35
|
-
// 处理 name
|
|
36
|
-
name = name.trim().replace(/\s+/g, '_');
|
|
37
|
-
/** 当前获取环境值 */
|
|
38
|
-
const _env = (platform === 'node' &&
|
|
39
|
-
(process.env[name.toUpperCase().concat('_DEV')] ??
|
|
40
|
-
process.env[name.toLowerCase().concat('_dev')])) ||
|
|
41
|
-
false;
|
|
42
|
-
const env = _env === 'false' ? false : _env === 'true' ? true : _env;
|
|
43
|
-
/** 默认 node 环境以获取到的环境值为准,而非 node 环境默认开启,并通过自定义的 @qqi/babel-plugin-remove-dog-calls 来进行过滤正式环境(环境值需要自定义) */
|
|
44
|
-
type = platform === 'node' ? setType(env ?? type) : true;
|
|
45
|
-
/// 原始的调用方法,在 type 值变化时会触发该值的更替
|
|
46
|
-
// 私有方法 error
|
|
47
|
-
const _privateFunc = {
|
|
48
|
-
error: blankCall,
|
|
49
|
-
warn: blankCall,
|
|
50
|
-
info: blankCall,
|
|
51
|
-
};
|
|
52
|
-
managePrint(type, _privateFunc, name);
|
|
53
|
-
/** 本体方法 */
|
|
54
|
-
const dog = (...str) => {
|
|
55
|
-
Reflect.apply(_privateFunc.info, this, str);
|
|
56
|
-
};
|
|
57
|
-
// 设置 prototype
|
|
58
|
-
Object.setPrototypeOf(dog, this);
|
|
59
|
-
// 设置属性和方法
|
|
60
|
-
Object.defineProperties(this, {
|
|
61
|
-
type: {
|
|
62
|
-
get() {
|
|
63
|
-
return type || false;
|
|
64
|
-
},
|
|
65
|
-
set(value) {
|
|
66
|
-
const new_type = setType(value);
|
|
67
|
-
if (new_type !== type) {
|
|
68
|
-
type = new_type;
|
|
69
|
-
managePrint(type, _privateFunc, name);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
error: {
|
|
74
|
-
value: (...str) => Reflect.apply(_privateFunc.error, this, str),
|
|
75
|
-
configurable: false,
|
|
76
|
-
enumerable: false,
|
|
77
|
-
writable: false,
|
|
78
|
-
},
|
|
79
|
-
warn: {
|
|
80
|
-
value: (...str) => Reflect.apply(_privateFunc.warn, this, str),
|
|
81
|
-
configurable: false,
|
|
82
|
-
enumerable: false,
|
|
83
|
-
writable: false,
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
return dog;
|
|
87
|
-
}
|
|
88
|
-
Dog.prototype.clear = () => {
|
|
89
|
-
if (platform === 'browser') {
|
|
90
|
-
console.clear();
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
console.log(esc.concat('c'));
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
*
|
|
98
|
-
* @param options 配置项
|
|
99
|
-
* @returns 函数对象
|
|
100
|
-
*
|
|
101
|
-
*/
|
|
102
|
-
const DogConstructor = createConstructor(Dog);
|
|
103
|
-
|
|
104
|
-
export { DogConstructor as Dog };
|
package/src/managePrint.cjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var aTypeOfJs = require('a-type-of-js');
|
|
4
|
-
var notSupport = require('./notSupport.cjs');
|
|
5
|
-
var platform = require('./platform.cjs');
|
|
6
|
-
var blankCall = require('./blankCall.cjs');
|
|
7
|
-
var printError = require('./printError.cjs');
|
|
8
|
-
var printWarn = require('./printWarn.cjs');
|
|
9
|
-
var printInfo = require('./printInfo.cjs');
|
|
10
|
-
var setType = require('./setType.cjs');
|
|
11
|
-
|
|
12
|
-
/** 管理是否打印 */
|
|
13
|
-
function managePrint(type, privateFunc, name) {
|
|
14
|
-
if (platform.platform === 'node') {
|
|
15
|
-
const dev = process.env[name.toUpperCase().concat('_DEV')] ||
|
|
16
|
-
process.env[name.toLowerCase().concat('_dev')];
|
|
17
|
-
/// 当前禁止使用打印
|
|
18
|
-
/// node 环境未配置 NAME_DEV 环境变量
|
|
19
|
-
/// 显式配置 NAME_DEV 环境变量为 false
|
|
20
|
-
if (type === false || aTypeOfJs.isUndefined(dev) || dev === 'false') {
|
|
21
|
-
return Reflect.apply(notSupport.notSupport, privateFunc, []);
|
|
22
|
-
}
|
|
23
|
-
/// 将显示配置环境变量的值给 type
|
|
24
|
-
if ([...setType.typeList, 'true', 'false'].includes(dev)) {
|
|
25
|
-
type = dev === 'true' ? 'all' : dev;
|
|
26
|
-
}
|
|
27
|
-
privateFunc.info = ['all', 'info', true].includes(type)
|
|
28
|
-
? printInfo.printInfo
|
|
29
|
-
: blankCall.blankCall;
|
|
30
|
-
privateFunc.error = ['all', 'error', true].includes(type)
|
|
31
|
-
? printError.printError
|
|
32
|
-
: blankCall.blankCall;
|
|
33
|
-
privateFunc.warn = ['all', 'warn', true].includes(type)
|
|
34
|
-
? printWarn.printWarn
|
|
35
|
-
: blankCall.blankCall;
|
|
36
|
-
}
|
|
37
|
-
// 在 非 node 环境始终执行,搭配 @qqi/babel-plugin-remove-dog-calls 使用
|
|
38
|
-
else {
|
|
39
|
-
if (type === false)
|
|
40
|
-
return Reflect.apply(notSupport.notSupport, privateFunc, []);
|
|
41
|
-
privateFunc.info = ['all', 'info', true].includes(type)
|
|
42
|
-
? printInfo.printInfo
|
|
43
|
-
: blankCall.blankCall;
|
|
44
|
-
privateFunc.error = ['all', 'error', true].includes(type)
|
|
45
|
-
? printError.printError
|
|
46
|
-
: blankCall.blankCall;
|
|
47
|
-
privateFunc.warn = ['all', 'warn', true].includes(type)
|
|
48
|
-
? printWarn.printWarn
|
|
49
|
-
: blankCall.blankCall;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
exports.managePrint = managePrint;
|
package/src/managePrint.d.ts
DELETED
package/src/managePrint.mjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { isUndefined } from 'a-type-of-js';
|
|
2
|
-
import { notSupport } from './notSupport.mjs';
|
|
3
|
-
import { platform } from './platform.mjs';
|
|
4
|
-
import { blankCall } from './blankCall.mjs';
|
|
5
|
-
import { printError } from './printError.mjs';
|
|
6
|
-
import { printWarn } from './printWarn.mjs';
|
|
7
|
-
import { printInfo } from './printInfo.mjs';
|
|
8
|
-
import { typeList } from './setType.mjs';
|
|
9
|
-
|
|
10
|
-
/** 管理是否打印 */
|
|
11
|
-
function managePrint(type, privateFunc, name) {
|
|
12
|
-
if (platform === 'node') {
|
|
13
|
-
const dev = process.env[name.toUpperCase().concat('_DEV')] ||
|
|
14
|
-
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/src/notSupport.cjs
DELETED
package/src/notSupport.d.ts
DELETED
package/src/notSupport.mjs
DELETED
package/src/parseError.cjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var colorPen = require('color-pen');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* 解析 error
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
function parseError(type) {
|
|
11
|
-
try {
|
|
12
|
-
throw new Error();
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
const parseErrorResult = (error.stack?.split('\n') || []).map(item => {
|
|
16
|
-
const reg = /at\s(.*)\s\((.*):(\d*):(\d*)\)/;
|
|
17
|
-
const res = reg.exec(item);
|
|
18
|
-
if (res) {
|
|
19
|
-
return {
|
|
20
|
-
name: res[1],
|
|
21
|
-
path: res[2],
|
|
22
|
-
line: res[3],
|
|
23
|
-
column: res[4],
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
name: '',
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
const result = parseErrorResult.filter(e => e.name !== '' && e.path !== undefined);
|
|
31
|
-
const res = result[3] ?? result[2] ?? result[1] ?? result[0];
|
|
32
|
-
const startStr = ` ${type === 'info' ? '💡' : type === 'error' ? '❌' : '⚠️ '} ${new Date().toLocaleString()} `;
|
|
33
|
-
const printStartPenStr = (type === 'info'
|
|
34
|
-
? colorPen.pen.bgCyan.brightWhite
|
|
35
|
-
: type === 'error'
|
|
36
|
-
? colorPen.pen.bgBlack.red
|
|
37
|
-
: colorPen.pen.bgBrightYellow.brightGreen)(startStr);
|
|
38
|
-
console.log(`${printStartPenStr} ${res?.name ?? ''} ${res?.line?.concat(' 行')} ${res?.column?.concat(' 列')}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
exports.parseError = parseError;
|
package/src/parseError.d.ts
DELETED
package/src/parseError.mjs
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/src/platform.cjs
DELETED
package/src/platform.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const platform: string;
|
package/src/platform.mjs
DELETED
package/src/printError.cjs
DELETED
package/src/printError.d.ts
DELETED
package/src/printError.mjs
DELETED
package/src/printInfo.cjs
DELETED
package/src/printInfo.d.ts
DELETED
package/src/printInfo.mjs
DELETED
package/src/printWarn.cjs
DELETED
package/src/printWarn.d.ts
DELETED
package/src/printWarn.mjs
DELETED
package/src/setType.cjs
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/src/setType.d.ts
DELETED
package/src/setType.mjs
DELETED