@qqi/log 0.0.0 → 0.0.2
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/package.json +2 -2
- package/src/index.cjs +24 -14
- package/src/index.d.ts +1 -2
- package/src/index.mjs +25 -15
- package/src/managePrint.cjs +11 -3
- package/src/managePrint.mjs +11 -3
- package/src/type.d.ts +1 -1
package/package.json
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
"module": "index.mjs",
|
|
4
4
|
"types": "index.d.ts",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.2",
|
|
7
7
|
"name": "@qqi/log",
|
|
8
8
|
"description": "原 @qqi/dev-log 中的 log 部分",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@color-pen/static": "^1.0.0",
|
|
12
|
-
"a-js-tools": "^1.0.
|
|
12
|
+
"a-js-tools": "^1.0.5",
|
|
13
13
|
"a-type-of-js": "^1.0.2",
|
|
14
14
|
"color-pen": "^2.0.11"
|
|
15
15
|
},
|
package/src/index.cjs
CHANGED
|
@@ -18,22 +18,32 @@ var _static = require('@color-pen/static');
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
function Dog(options) {
|
|
21
|
-
|
|
21
|
+
if (aTypeOfJs.isUndefined(options))
|
|
22
|
+
options = {
|
|
23
|
+
name: aJsTools.getRandomString(10),
|
|
24
|
+
type: false,
|
|
25
|
+
};
|
|
26
|
+
if (aTypeOfJs.isBoolean(options))
|
|
27
|
+
options = {
|
|
28
|
+
name: aJsTools.getRandomString(10),
|
|
29
|
+
type: options,
|
|
30
|
+
};
|
|
31
|
+
if (aTypeOfJs.isString(options))
|
|
32
|
+
options = {
|
|
33
|
+
name: options,
|
|
34
|
+
type: false,
|
|
35
|
+
};
|
|
36
|
+
let { name = '', type = false } = options;
|
|
22
37
|
// 处理 name
|
|
23
|
-
name =
|
|
24
|
-
|
|
25
|
-
: aJsTools.getRandomString(10);
|
|
38
|
+
name = name.trim().replace(/\s+/g, '_');
|
|
39
|
+
/** 当前获取环境值 */
|
|
26
40
|
const _env = (platform.platform === 'node' &&
|
|
27
41
|
(process.env[name.toUpperCase().concat('_DEV')] ??
|
|
28
42
|
process.env[name.toLowerCase().concat('_dev')])) ||
|
|
29
43
|
false;
|
|
30
|
-
const env =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
? true
|
|
34
|
-
: _env;
|
|
35
|
-
/** 私有属性 */
|
|
36
|
-
type = setType.setType(env ?? type);
|
|
44
|
+
const env = _env === 'false' ? false : _env === 'true' ? true : _env;
|
|
45
|
+
/** 默认 node 环境以获取到的环境值为准,而非 node 环境默认开启,并通过自定义的 @qqi/babel-plugin-remove-dog-calls 来进行过滤正式环境(环境值需要自定义) */
|
|
46
|
+
type = platform.platform === 'node' ? setType.setType(env ?? type) : true;
|
|
37
47
|
/// 原始的调用方法,在 type 值变化时会触发该值的更替
|
|
38
48
|
// 私有方法 error
|
|
39
49
|
const _privateFunc = {
|
|
@@ -54,11 +64,11 @@ function Dog(options) {
|
|
|
54
64
|
get() {
|
|
55
65
|
return type || false;
|
|
56
66
|
},
|
|
57
|
-
set(
|
|
58
|
-
const new_type = setType.setType(
|
|
67
|
+
set(value) {
|
|
68
|
+
const new_type = setType.setType(value);
|
|
59
69
|
if (new_type !== type) {
|
|
60
70
|
type = new_type;
|
|
61
|
-
managePrint.managePrint(
|
|
71
|
+
managePrint.managePrint(type, _privateFunc, name);
|
|
62
72
|
}
|
|
63
73
|
},
|
|
64
74
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { DevLog, DogOptions } from './type';
|
|
2
1
|
/**
|
|
3
2
|
*
|
|
4
3
|
* @param options 配置项
|
|
5
4
|
* @returns 函数对象
|
|
6
5
|
*
|
|
7
6
|
*/
|
|
8
|
-
declare const DogConstructor:
|
|
7
|
+
declare const DogConstructor: any;
|
|
9
8
|
export { DogConstructor as Dog };
|
package/src/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createConstructor, getRandomString } from 'a-js-tools';
|
|
|
2
2
|
import { setType } from './setType.mjs';
|
|
3
3
|
import { blankCall } from './blankCall.mjs';
|
|
4
4
|
import { managePrint } from './managePrint.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { isUndefined, isBoolean, isString } from 'a-type-of-js';
|
|
6
6
|
import { platform } from './platform.mjs';
|
|
7
7
|
import { esc } from '@color-pen/static';
|
|
8
8
|
|
|
@@ -16,22 +16,32 @@ import { esc } from '@color-pen/static';
|
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
18
|
function Dog(options) {
|
|
19
|
-
|
|
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;
|
|
20
35
|
// 处理 name
|
|
21
|
-
name =
|
|
22
|
-
|
|
23
|
-
: getRandomString(10);
|
|
36
|
+
name = name.trim().replace(/\s+/g, '_');
|
|
37
|
+
/** 当前获取环境值 */
|
|
24
38
|
const _env = (platform === 'node' &&
|
|
25
39
|
(process.env[name.toUpperCase().concat('_DEV')] ??
|
|
26
40
|
process.env[name.toLowerCase().concat('_dev')])) ||
|
|
27
41
|
false;
|
|
28
|
-
const env =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
? true
|
|
32
|
-
: _env;
|
|
33
|
-
/** 私有属性 */
|
|
34
|
-
type = setType(env ?? type);
|
|
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;
|
|
35
45
|
/// 原始的调用方法,在 type 值变化时会触发该值的更替
|
|
36
46
|
// 私有方法 error
|
|
37
47
|
const _privateFunc = {
|
|
@@ -52,11 +62,11 @@ function Dog(options) {
|
|
|
52
62
|
get() {
|
|
53
63
|
return type || false;
|
|
54
64
|
},
|
|
55
|
-
set(
|
|
56
|
-
const new_type = setType(
|
|
65
|
+
set(value) {
|
|
66
|
+
const new_type = setType(value);
|
|
57
67
|
if (new_type !== type) {
|
|
58
68
|
type = new_type;
|
|
59
|
-
managePrint(
|
|
69
|
+
managePrint(type, _privateFunc, name);
|
|
60
70
|
}
|
|
61
71
|
},
|
|
62
72
|
},
|
package/src/managePrint.cjs
CHANGED
|
@@ -36,9 +36,17 @@ function managePrint(type, privateFunc, name) {
|
|
|
36
36
|
}
|
|
37
37
|
// 在 非 node 环境始终执行,搭配 @qqi/babel-plugin-remove-dog-calls 使用
|
|
38
38
|
else {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
privateFunc.
|
|
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;
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
package/src/managePrint.mjs
CHANGED
|
@@ -34,9 +34,17 @@ function managePrint(type, privateFunc, name) {
|
|
|
34
34
|
}
|
|
35
35
|
// 在 非 node 环境始终执行,搭配 @qqi/babel-plugin-remove-dog-calls 使用
|
|
36
36
|
else {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
privateFunc.
|
|
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;
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
|
package/src/type.d.ts
CHANGED