@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/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) <2025>
|
|
3
|
+
Copyright (c) <2025> <Mr.MudBean>
|
|
4
4
|
|
|
5
5
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,7 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
16
16
|
|
|
17
17
|
# MIT 许可证
|
|
18
18
|
|
|
19
|
-
版权所有 (c) [2025] [
|
|
19
|
+
版权所有 (c) [2025] [泥豆君]
|
|
20
20
|
|
|
21
21
|
特此免费授予任何获得本软件及相关文档文件(以下简称“软件”)副本的人不受限制地处置该软件的权利,包括不受限制地使用、复制、修改、合并、发布、分发、再许可和/或出售该软件副本的权利,并允许向其提供该软件的人这样做,但须遵守以下条件:
|
|
22
22
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @qqi/log
|
|
2
2
|
|
|
3
|
-
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/@qqi/log) [?logo=github>)](https://github.com/
|
|
3
|
+
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/@qqi/log) [?logo=github>)](https://github.com/MeMudBean/qqi/issues)
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
@@ -32,6 +32,16 @@ dog('你好'); // 该值是否打印还依赖于环境变量中有没有配置 `
|
|
|
32
32
|
a_node_tools_dev=true npm run dev
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
### 折叠同名方法打印消息
|
|
36
|
+
|
|
37
|
+
使用 `fold` 参数 :
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { Dog } from '@qqi/log';
|
|
41
|
+
|
|
42
|
+
const dog = Dog();
|
|
43
|
+
```
|
|
44
|
+
|
|
35
45
|
## 文档地址
|
|
36
46
|
|
|
37
47
|
参看 [https://earthnut.dev/npm/qqi/log](https://earthnut.dev/npm/qqi/log)
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _static = require('@color-pen/static');
|
|
4
|
+
var aJsTools = require('a-js-tools');
|
|
5
|
+
var colorPen = require('color-pen');
|
|
6
|
+
var util = require('./util.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param options 配置项
|
|
11
|
+
* @returns 函数对象
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
var DogConstructor = aJsTools.createConstructor(Dog);
|
|
15
|
+
/**
|
|
16
|
+
* ## 创建 dev log 工厂函数
|
|
17
|
+
* @param options - 配置项
|
|
18
|
+
* @returns - dev log 工厂函数
|
|
19
|
+
*/
|
|
20
|
+
function Dog(options) {
|
|
21
|
+
var _this = this;
|
|
22
|
+
var _p = util.parseOption(options);
|
|
23
|
+
this.name = _p.name || aJsTools.getRandomString(12);
|
|
24
|
+
this.fold = Boolean(_p.fold);
|
|
25
|
+
var env = util.getEnv(this.name);
|
|
26
|
+
var type = _p.type || false;
|
|
27
|
+
this.mark = '';
|
|
28
|
+
/** 默认 node 环境以获取到的环境值为准,而非 node 环境默认开启,并通过自定义的 @qqi/babel-plugin-remove-dog-calls 来进行过滤正式环境(环境值需要自定义) */
|
|
29
|
+
this.type = util.platform === 'node' ? util.setType(env !== null && env !== void 0 ? env : type) : true;
|
|
30
|
+
/**
|
|
31
|
+
* ## 解析 error
|
|
32
|
+
* @param type
|
|
33
|
+
*/
|
|
34
|
+
var prefix = function (type) {
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
36
|
+
try {
|
|
37
|
+
throw new Error();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
var parseErrorResult = (((_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n')) || []).map(function (item) {
|
|
41
|
+
var reg = /at\s(.*)\s\((.*):(\d*):(\d*)\)/;
|
|
42
|
+
var res = reg.exec(item);
|
|
43
|
+
if (res) {
|
|
44
|
+
return {
|
|
45
|
+
name: res[1],
|
|
46
|
+
path: res[2],
|
|
47
|
+
line: res[3],
|
|
48
|
+
column: res[4],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
name: '',
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
var result = parseErrorResult.filter(function (e) { return e.name !== '' && e.path !== undefined; });
|
|
56
|
+
var res = (_d = (_c = (_b = result[3]) !== null && _b !== void 0 ? _b : result[2]) !== null && _c !== void 0 ? _c : result[1]) !== null && _d !== void 0 ? _d : result[0];
|
|
57
|
+
var startStr = " ".concat(type === 'info' ? '💡' : type === 'error' ? '❌' : '⚠️ ', " ").concat(new Date().toLocaleString(), " ");
|
|
58
|
+
var printStartPenStr = (type === 'info'
|
|
59
|
+
? colorPen.bgCyanPen.brightWhite
|
|
60
|
+
: type === 'error'
|
|
61
|
+
? colorPen.bgBlackPen.red
|
|
62
|
+
: colorPen.bgBrightYellowPen.brightGreen)(startStr);
|
|
63
|
+
var mark = (_e = res === null || res === void 0 ? void 0 : res.name) !== null && _e !== void 0 ? _e : '';
|
|
64
|
+
if (_this.fold && mark) {
|
|
65
|
+
if (mark === _this.mark) ;
|
|
66
|
+
else {
|
|
67
|
+
if (_this.mark) {
|
|
68
|
+
console.groupEnd();
|
|
69
|
+
}
|
|
70
|
+
console.groupCollapsed(mark);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
_this.mark = mark;
|
|
74
|
+
return "".concat(printStartPenStr, " ").concat(mark, " ").concat((_f = res === null || res === void 0 ? void 0 : res.line) === null || _f === void 0 ? void 0 : _f.concat(' 行'), " ").concat((_g = res === null || res === void 0 ? void 0 : res.column) === null || _g === void 0 ? void 0 : _g.concat(' 列'));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
this.info = function () {
|
|
78
|
+
var msg = [];
|
|
79
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
80
|
+
msg[_i] = arguments[_i];
|
|
81
|
+
}
|
|
82
|
+
if (_this.type === 'all' || _this.type === 'info' || _this.type === true) {
|
|
83
|
+
var _prefix = prefix('info');
|
|
84
|
+
msg.unshift(_prefix);
|
|
85
|
+
console.log.apply(console, msg);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* @param msg
|
|
90
|
+
*/
|
|
91
|
+
this.warn = function () {
|
|
92
|
+
var msg = [];
|
|
93
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
94
|
+
msg[_i] = arguments[_i];
|
|
95
|
+
}
|
|
96
|
+
if (_this.type === 'all' || _this.type === 'warn' || _this.type === true) {
|
|
97
|
+
var _prefix = prefix('warn');
|
|
98
|
+
msg.unshift(_prefix);
|
|
99
|
+
console.warn.apply(console, msg);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* @param msg
|
|
105
|
+
*/
|
|
106
|
+
this.error = function () {
|
|
107
|
+
var msg = [];
|
|
108
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
109
|
+
msg[_i] = arguments[_i];
|
|
110
|
+
}
|
|
111
|
+
if (_this.type === 'all' || _this.type === 'error' || _this.type === true) {
|
|
112
|
+
var _prefix = prefix('error');
|
|
113
|
+
msg.unshift(_prefix);
|
|
114
|
+
console.error.apply(console, msg);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* 本体方法
|
|
119
|
+
* @param str
|
|
120
|
+
*/
|
|
121
|
+
var dog = function () {
|
|
122
|
+
var str = [];
|
|
123
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
124
|
+
str[_i] = arguments[_i];
|
|
125
|
+
}
|
|
126
|
+
_this.info(str);
|
|
127
|
+
};
|
|
128
|
+
// 设置 prototype
|
|
129
|
+
Object.setPrototypeOf(dog, this);
|
|
130
|
+
return dog;
|
|
131
|
+
}
|
|
132
|
+
/** 原型上添加 clear 方法 */
|
|
133
|
+
Dog.prototype.clear = function () {
|
|
134
|
+
if (util.platform === 'browser') {
|
|
135
|
+
console.clear();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
console.log(_static.esc.concat('c'));
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
function DogVirtualImt() {
|
|
145
|
+
/**
|
|
146
|
+
* 模拟类的构建
|
|
147
|
+
* @param _arg
|
|
148
|
+
*/
|
|
149
|
+
var _dev = function () {
|
|
150
|
+
};
|
|
151
|
+
Object.setPrototypeOf(_dev, this);
|
|
152
|
+
Object.defineProperties(this, {
|
|
153
|
+
info: {
|
|
154
|
+
value: function () {
|
|
155
|
+
},
|
|
156
|
+
configurable: false,
|
|
157
|
+
writable: false,
|
|
158
|
+
},
|
|
159
|
+
warn: {
|
|
160
|
+
value: function () {
|
|
161
|
+
},
|
|
162
|
+
configurable: false,
|
|
163
|
+
writable: false,
|
|
164
|
+
},
|
|
165
|
+
error: {
|
|
166
|
+
value: function () {
|
|
167
|
+
},
|
|
168
|
+
configurable: false,
|
|
169
|
+
writable: false,
|
|
170
|
+
},
|
|
171
|
+
type: {
|
|
172
|
+
get: function () {
|
|
173
|
+
return false;
|
|
174
|
+
},
|
|
175
|
+
set: function (_) { },
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
return _dev;
|
|
179
|
+
}
|
|
180
|
+
DogVirtualImt.prototype.clear = console.clear;
|
|
181
|
+
/** 虚拟狗,没有实现不打印 */
|
|
182
|
+
var DogVirtualConstructor = aJsTools.createConstructor(DogVirtualImt);
|
|
183
|
+
|
|
184
|
+
exports.Dog = DogConstructor;
|
|
185
|
+
exports.DogVirtual = DogVirtualConstructor;
|
package/cjs/util.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var aJsTools = require('a-js-tools');
|
|
4
|
+
var aTypeOfJs = require('a-type-of-js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module @qqi/log/util
|
|
9
|
+
* @file util.ts
|
|
10
|
+
* @description 工具
|
|
11
|
+
* @author MrMudBean <Mr.MudBean@outlook.com>
|
|
12
|
+
* @license MIT
|
|
13
|
+
* @copyright 2026 ©️ MrMudBean
|
|
14
|
+
* @since 2026-01-28 03:11
|
|
15
|
+
* @version 1.0.1
|
|
16
|
+
* @lastModified 2026-01-28 04:34
|
|
17
|
+
*/
|
|
18
|
+
var typeList = [
|
|
19
|
+
false,
|
|
20
|
+
true,
|
|
21
|
+
'all',
|
|
22
|
+
'info',
|
|
23
|
+
'error',
|
|
24
|
+
'warn',
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* ## 解析参数
|
|
28
|
+
* @param options
|
|
29
|
+
*/
|
|
30
|
+
function parseOption(options) {
|
|
31
|
+
var result = {
|
|
32
|
+
name: aJsTools.getRandomString(10),
|
|
33
|
+
type: false,
|
|
34
|
+
fold: false,
|
|
35
|
+
};
|
|
36
|
+
if (aTypeOfJs.isUndefined(options))
|
|
37
|
+
return result;
|
|
38
|
+
if (aTypeOfJs.isBoolean(options)) {
|
|
39
|
+
result.type = options;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
if (aTypeOfJs.isString(options)) {
|
|
43
|
+
// 处理 name
|
|
44
|
+
result.name = options.trim().replace(/\s+/g, '_');
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
if (aTypeOfJs.isString(options.name)) {
|
|
48
|
+
result.name = options.name.trim().replace(/\s+/g, '_');
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
return options;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 获取当前的环境变量
|
|
55
|
+
* @param name
|
|
56
|
+
*/
|
|
57
|
+
function getEnv(name) {
|
|
58
|
+
var _a;
|
|
59
|
+
if (name === void 0) { name = aJsTools.getRandomString(10); }
|
|
60
|
+
/** 当前获取环境值 */
|
|
61
|
+
var _env = false;
|
|
62
|
+
if (platform === 'node' && ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.process) === null || _a === void 0 ? void 0 : _a.env)) {
|
|
63
|
+
var processEnv = process.env;
|
|
64
|
+
_env =
|
|
65
|
+
processEnv[name.toUpperCase().concat('_DEV')] ||
|
|
66
|
+
processEnv[name.toLowerCase().concat('_dev')] ||
|
|
67
|
+
false;
|
|
68
|
+
}
|
|
69
|
+
var env = _env === 'false' ? false : _env === 'true' ? true : _env;
|
|
70
|
+
return env;
|
|
71
|
+
}
|
|
72
|
+
var platform = aJsTools.isNode() ? 'node' : 'browser';
|
|
73
|
+
/**
|
|
74
|
+
* 设置 type 的类型
|
|
75
|
+
* @param type 新的类型
|
|
76
|
+
*/
|
|
77
|
+
function setType(type) {
|
|
78
|
+
if (typeList.includes(type))
|
|
79
|
+
return type;
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exports.getEnv = getEnv;
|
|
84
|
+
exports.parseOption = parseOption;
|
|
85
|
+
exports.platform = platform;
|
|
86
|
+
exports.setType = setType;
|
|
87
|
+
exports.typeList = typeList;
|