@qqi/log 0.0.0 → 0.0.1

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.mjs",
4
4
  "types": "index.d.ts",
5
5
  "type": "module",
6
- "version": "0.0.0",
6
+ "version": "0.0.1",
7
7
  "name": "@qqi/log",
8
8
  "description": "原 @qqi/dev-log 中的 log 部分",
9
9
  "license": "MIT",
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
- let { name = '', type = false } = options || {};
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 = aTypeOfJs.isString(name)
24
- ? name.trim().replace(/\s+/g, '_')
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 = aTypeOfJs.isUndefined(_env) || _env === 'false'
31
- ? false
32
- : _env === 'true'
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 = {
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 { isString, isUndefined } from 'a-type-of-js';
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
- let { name = '', type = false } = 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;
20
35
  // 处理 name
21
- name = isString(name)
22
- ? name.trim().replace(/\s+/g, '_')
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 = isUndefined(_env) || _env === 'false'
29
- ? false
30
- : _env === 'true'
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 = {
@@ -36,9 +36,17 @@ function managePrint(type, privateFunc, name) {
36
36
  }
37
37
  // 在 非 node 环境始终执行,搭配 @qqi/babel-plugin-remove-dog-calls 使用
38
38
  else {
39
- privateFunc.info = printInfo.printInfo;
40
- privateFunc.warn = printWarn.printWarn;
41
- privateFunc.error = printError.printError;
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
 
@@ -34,9 +34,17 @@ function managePrint(type, privateFunc, name) {
34
34
  }
35
35
  // 在 非 node 环境始终执行,搭配 @qqi/babel-plugin-remove-dog-calls 使用
36
36
  else {
37
- privateFunc.info = printInfo;
38
- privateFunc.warn = printWarn;
39
- privateFunc.error = printError;
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
@@ -33,4 +33,4 @@ export type DogOptions = {
33
33
  *
34
34
  */
35
35
  name?: string;
36
- };
36
+ } | string | boolean;