@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/es/index.js ADDED
@@ -0,0 +1,182 @@
1
+ import { esc } from '@color-pen/static';
2
+ import { createConstructor, getRandomString } from 'a-js-tools';
3
+ import { bgCyanPen, bgBlackPen, bgBrightYellowPen } from 'color-pen';
4
+ import { parseOption, getEnv, platform, setType } from './util.js';
5
+
6
+ /**
7
+ *
8
+ * @param options 配置项
9
+ * @returns 函数对象
10
+ *
11
+ */
12
+ var DogConstructor = createConstructor(Dog);
13
+ /**
14
+ * ## 创建 dev log 工厂函数
15
+ * @param options - 配置项
16
+ * @returns - dev log 工厂函数
17
+ */
18
+ function Dog(options) {
19
+ var _this = this;
20
+ var _p = parseOption(options);
21
+ this.name = _p.name || getRandomString(12);
22
+ this.fold = Boolean(_p.fold);
23
+ var env = getEnv(this.name);
24
+ var type = _p.type || false;
25
+ this.mark = '';
26
+ /** 默认 node 环境以获取到的环境值为准,而非 node 环境默认开启,并通过自定义的 @qqi/babel-plugin-remove-dog-calls 来进行过滤正式环境(环境值需要自定义) */
27
+ this.type = platform === 'node' ? setType(env !== null && env !== void 0 ? env : type) : true;
28
+ /**
29
+ * ## 解析 error
30
+ * @param type
31
+ */
32
+ var prefix = function (type) {
33
+ var _a, _b, _c, _d, _e, _f, _g;
34
+ try {
35
+ throw new Error();
36
+ }
37
+ catch (error) {
38
+ var parseErrorResult = (((_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n')) || []).map(function (item) {
39
+ var reg = /at\s(.*)\s\((.*):(\d*):(\d*)\)/;
40
+ var res = reg.exec(item);
41
+ if (res) {
42
+ return {
43
+ name: res[1],
44
+ path: res[2],
45
+ line: res[3],
46
+ column: res[4],
47
+ };
48
+ }
49
+ return {
50
+ name: '',
51
+ };
52
+ });
53
+ var result = parseErrorResult.filter(function (e) { return e.name !== '' && e.path !== undefined; });
54
+ 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];
55
+ var startStr = " ".concat(type === 'info' ? '💡' : type === 'error' ? '❌' : '⚠️ ', " ").concat(new Date().toLocaleString(), " ");
56
+ var printStartPenStr = (type === 'info'
57
+ ? bgCyanPen.brightWhite
58
+ : type === 'error'
59
+ ? bgBlackPen.red
60
+ : bgBrightYellowPen.brightGreen)(startStr);
61
+ var mark = (_e = res === null || res === void 0 ? void 0 : res.name) !== null && _e !== void 0 ? _e : '';
62
+ if (_this.fold && mark) {
63
+ if (mark === _this.mark) ;
64
+ else {
65
+ if (_this.mark) {
66
+ console.groupEnd();
67
+ }
68
+ console.groupCollapsed(mark);
69
+ }
70
+ }
71
+ _this.mark = mark;
72
+ 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(' 列'));
73
+ }
74
+ };
75
+ this.info = function () {
76
+ var msg = [];
77
+ for (var _i = 0; _i < arguments.length; _i++) {
78
+ msg[_i] = arguments[_i];
79
+ }
80
+ if (_this.type === 'all' || _this.type === 'info' || _this.type === true) {
81
+ var _prefix = prefix('info');
82
+ msg.unshift(_prefix);
83
+ console.log.apply(console, msg);
84
+ }
85
+ };
86
+ /**
87
+ * @param msg
88
+ */
89
+ this.warn = function () {
90
+ var msg = [];
91
+ for (var _i = 0; _i < arguments.length; _i++) {
92
+ msg[_i] = arguments[_i];
93
+ }
94
+ if (_this.type === 'all' || _this.type === 'warn' || _this.type === true) {
95
+ var _prefix = prefix('warn');
96
+ msg.unshift(_prefix);
97
+ console.warn.apply(console, msg);
98
+ }
99
+ };
100
+ /**
101
+ *
102
+ * @param msg
103
+ */
104
+ this.error = function () {
105
+ var msg = [];
106
+ for (var _i = 0; _i < arguments.length; _i++) {
107
+ msg[_i] = arguments[_i];
108
+ }
109
+ if (_this.type === 'all' || _this.type === 'error' || _this.type === true) {
110
+ var _prefix = prefix('error');
111
+ msg.unshift(_prefix);
112
+ console.error.apply(console, msg);
113
+ }
114
+ };
115
+ /**
116
+ * 本体方法
117
+ * @param str
118
+ */
119
+ var dog = function () {
120
+ var str = [];
121
+ for (var _i = 0; _i < arguments.length; _i++) {
122
+ str[_i] = arguments[_i];
123
+ }
124
+ _this.info(str);
125
+ };
126
+ // 设置 prototype
127
+ Object.setPrototypeOf(dog, this);
128
+ return dog;
129
+ }
130
+ /** 原型上添加 clear 方法 */
131
+ Dog.prototype.clear = function () {
132
+ if (platform === 'browser') {
133
+ console.clear();
134
+ }
135
+ else {
136
+ console.log(esc.concat('c'));
137
+ }
138
+ };
139
+ /**
140
+ *
141
+ */
142
+ function DogVirtualImt() {
143
+ /**
144
+ * 模拟类的构建
145
+ * @param _arg
146
+ */
147
+ var _dev = function () {
148
+ };
149
+ Object.setPrototypeOf(_dev, this);
150
+ Object.defineProperties(this, {
151
+ info: {
152
+ value: function () {
153
+ },
154
+ configurable: false,
155
+ writable: false,
156
+ },
157
+ warn: {
158
+ value: function () {
159
+ },
160
+ configurable: false,
161
+ writable: false,
162
+ },
163
+ error: {
164
+ value: function () {
165
+ },
166
+ configurable: false,
167
+ writable: false,
168
+ },
169
+ type: {
170
+ get: function () {
171
+ return false;
172
+ },
173
+ set: function (_) { },
174
+ },
175
+ });
176
+ return _dev;
177
+ }
178
+ DogVirtualImt.prototype.clear = console.clear;
179
+ /** 虚拟狗,没有实现不打印 */
180
+ var DogVirtualConstructor = createConstructor(DogVirtualImt);
181
+
182
+ export { DogConstructor as Dog, DogVirtualConstructor as DogVirtual };
@@ -0,0 +1,17 @@
1
+ declare namespace _default {
2
+ namespace input {
3
+ let index: string;
4
+ }
5
+ let output: {
6
+ format: string;
7
+ entryFileNames: string;
8
+ preserveModules: boolean;
9
+ preserveModulesRoot: string;
10
+ sourcemap: boolean;
11
+ exports: string;
12
+ dir: string;
13
+ }[];
14
+ let external: (id: string) => boolean;
15
+ let plugins: import("rollup").Plugin<any>[];
16
+ }
17
+ export default _default;
@@ -0,0 +1,14 @@
1
+ declare namespace _default {
2
+ let input: string;
3
+ namespace output {
4
+ let format: string;
5
+ let entryFileNames: string;
6
+ let preserveModules: boolean;
7
+ let sourcemap: boolean;
8
+ let exports: string;
9
+ let dir: string;
10
+ }
11
+ let external: (id: string) => boolean;
12
+ let plugins: import("rollup").Plugin<any>[];
13
+ }
14
+ export default _default;
@@ -7,3 +7,7 @@ import { DevLog, DogOptions } from './type';
7
7
  */
8
8
  declare const DogConstructor: import("a-js-tools").CreateConstructor<DevLog, [options?: DogOptions | undefined]>;
9
9
  export { DogConstructor as Dog };
10
+ export type { DevLogType, DevLog } from './type';
11
+ /** 虚拟狗,没有实现不打印 */
12
+ declare const DogVirtualConstructor: import("a-js-tools").CreateConstructor<DevLog, []>;
13
+ export { DogVirtualConstructor as DogVirtual };
@@ -2,14 +2,20 @@ export type DevLogType = boolean | 'info' | 'error' | 'all' | 'warn';
2
2
  export type DevLog = {
3
3
  /** 打印信息本当作为 info 信息,在 type 为 `false`、`error`、`warn` 时不打印 */
4
4
  (...str: unknown[]): void;
5
+ /** 当打印的版本为错误信息,在 type 为 `false`、`error`、`warn` 时不打印 */
6
+ info: (...str: unknown[]) => void;
5
7
  /** 当打印的版本为错误信息,在 type 为 `false`、`info`、`warn` 时不打印 */
6
8
  error: (...str: unknown[]) => void;
7
9
  /** 当打印的版本为警示信息,在 type 为 `false`、`info`、`error` 时不打印 */
8
10
  warn: (...str: unknown[]) => void;
9
11
  /** node 平台执行依据 */
10
- name: '';
12
+ name: string;
13
+ /** 同名(方法)折叠 */
14
+ fold: boolean;
11
15
  /** 开启打印的类型 */
12
16
  type: DevLogType;
17
+ /** 当前标记的名 */
18
+ mark: string;
13
19
  /** 清除控制台 */
14
20
  clear: () => void;
15
21
  };
@@ -21,16 +27,12 @@ export interface PrivateFunc {
21
27
  }
22
28
  export type DogOptions = {
23
29
  /**
24
- * ### 类型
25
- *
30
+ * ## 类型
26
31
  * 但是该值将被传入的系统参数覆盖
27
- *
28
32
  */
29
33
  type?: DevLogType;
30
- /**
31
- * 该值将以 name_dev 的形式配置允许打印
32
- *
33
- *
34
- */
34
+ /** 该值将以 name_dev 的形式配置允许打印 */
35
35
  name?: string;
36
+ /** 同名文件打印消息是否折叠(控制台效果不明显) */
37
+ fold?: boolean;
36
38
  } | string | boolean;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module @qqi/log/util
4
+ * @file util.ts
5
+ * @description 工具
6
+ * @author MrMudBean <Mr.MudBean@outlook.com>
7
+ * @license MIT
8
+ * @copyright 2026 ©️ MrMudBean
9
+ * @since 2026-01-28 03:11
10
+ * @version 1.0.1
11
+ * @lastModified 2026-01-28 04:34
12
+ */
13
+ import { DevLogType } from '@qqi/log';
14
+ import { DogOptions } from './type';
15
+ export declare const typeList: DevLogType[];
16
+ /**
17
+ * ## 解析参数
18
+ * @param options
19
+ */
20
+ export declare function parseOption(options?: DogOptions): {
21
+ name?: string;
22
+ type?: DevLogType;
23
+ fold?: boolean;
24
+ };
25
+ /**
26
+ * 获取当前的环境变量
27
+ * @param name
28
+ */
29
+ export declare function getEnv(name?: string): DevLogType;
30
+ export declare const platform: string;
31
+ /**
32
+ * 设置 type 的类型
33
+ * @param type 新的类型
34
+ */
35
+ export declare function setType(type: DevLogType): DevLogType;
package/es/util.js ADDED
@@ -0,0 +1,81 @@
1
+ import { isNode, getRandomString } from 'a-js-tools';
2
+ import { isUndefined, isBoolean, isString } from 'a-type-of-js';
3
+
4
+ /**
5
+ * @packageDocumentation
6
+ * @module @qqi/log/util
7
+ * @file util.ts
8
+ * @description 工具
9
+ * @author MrMudBean <Mr.MudBean@outlook.com>
10
+ * @license MIT
11
+ * @copyright 2026 ©️ MrMudBean
12
+ * @since 2026-01-28 03:11
13
+ * @version 1.0.1
14
+ * @lastModified 2026-01-28 04:34
15
+ */
16
+ var typeList = [
17
+ false,
18
+ true,
19
+ 'all',
20
+ 'info',
21
+ 'error',
22
+ 'warn',
23
+ ];
24
+ /**
25
+ * ## 解析参数
26
+ * @param options
27
+ */
28
+ function parseOption(options) {
29
+ var result = {
30
+ name: getRandomString(10),
31
+ type: false,
32
+ fold: false,
33
+ };
34
+ if (isUndefined(options))
35
+ return result;
36
+ if (isBoolean(options)) {
37
+ result.type = options;
38
+ return result;
39
+ }
40
+ if (isString(options)) {
41
+ // 处理 name
42
+ result.name = options.trim().replace(/\s+/g, '_');
43
+ return result;
44
+ }
45
+ if (isString(options.name)) {
46
+ result.name = options.name.trim().replace(/\s+/g, '_');
47
+ return result;
48
+ }
49
+ return options;
50
+ }
51
+ /**
52
+ * 获取当前的环境变量
53
+ * @param name
54
+ */
55
+ function getEnv(name) {
56
+ var _a;
57
+ if (name === void 0) { name = getRandomString(10); }
58
+ /** 当前获取环境值 */
59
+ var _env = false;
60
+ if (platform === 'node' && ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.process) === null || _a === void 0 ? void 0 : _a.env)) {
61
+ var processEnv = process.env;
62
+ _env =
63
+ processEnv[name.toUpperCase().concat('_DEV')] ||
64
+ processEnv[name.toLowerCase().concat('_dev')] ||
65
+ false;
66
+ }
67
+ var env = _env === 'false' ? false : _env === 'true' ? true : _env;
68
+ return env;
69
+ }
70
+ var platform = isNode() ? 'node' : 'browser';
71
+ /**
72
+ * 设置 type 的类型
73
+ * @param type 新的类型
74
+ */
75
+ function setType(type) {
76
+ if (typeList.includes(type))
77
+ return type;
78
+ return false;
79
+ }
80
+
81
+ export { getEnv, parseOption, platform, setType, typeList };
package/package.json CHANGED
@@ -1,63 +1,59 @@
1
1
  {
2
- "main": "index.cjs",
3
- "module": "index.mjs",
4
- "types": "index.d.ts",
5
2
  "type": "module",
6
- "version": "0.1.1",
3
+ "version": "1.1.0",
7
4
  "name": "@qqi/log",
5
+ "main": "cjs/index.js",
6
+ "module": "es/index.js",
7
+ "types": "es/src/index.d.ts",
8
+ "author": {
9
+ "name": "泥豆君",
10
+ "email": "Mr.MudBean@outlook.com",
11
+ "url": "https://earthnut.dev"
12
+ },
8
13
  "description": "原 @qqi/dev-log 中的 log 部分",
14
+ "sideEffects": false,
9
15
  "license": "MIT",
10
- "dependencies": {
11
- "@color-pen/static": "^1.0.1",
12
- "a-js-tools": "^1.0.10",
13
- "a-type-of-js": "^1.0.7",
14
- "color-pen": "^2.0.13"
15
- },
16
- "publishConfig": {
17
- "access": "public",
18
- "registry": "https://registry.npmjs.org/"
19
- },
20
16
  "files": [
21
- "index.d.ts",
22
- "index.mjs",
23
- "index.cjs",
24
- "src"
17
+ "cjs",
18
+ "es",
19
+ "LICENSE",
20
+ "README.md"
25
21
  ],
26
22
  "exports": {
27
23
  ".": {
28
- "import": {
29
- "default": "./index.mjs",
30
- "types": "./index.d.ts"
31
- },
32
- "require": {
33
- "default": "./index.cjs",
34
- "types": "./index.d.ts"
35
- }
24
+ "import": "./es/index.js",
25
+ "default": "./es/index.js",
26
+ "require": "./cjs/index.js",
27
+ "types": "./es/src/index.d.ts"
36
28
  }
37
29
  },
30
+ "keywords": [
31
+ "log"
32
+ ],
33
+ "homepage": "https://earthnut.dev/npm/qqi/log",
34
+ "dependencies": {
35
+ "@color-pen/static": "^1.1.1",
36
+ "a-js-tools": "^2.0.1",
37
+ "a-type-of-js": "^2.0.0",
38
+ "color-pen": "^3.0.0"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/MrMudBean/qqi/issues",
42
+ "email": "Mr.MudBean@outlook.com"
43
+ },
38
44
  "repository": {
39
45
  "type": "git",
40
- "url": "git+https://github.com/earthnutDev/qqi.git"
46
+ "url": "git+https://github.com/MrMudBean/qqi.git",
47
+ "directory": "packages/log"
41
48
  },
42
- "author": {
43
- "name": "🥜",
44
- "email": "earthnut.dev@outlook.com",
45
- "url": "https://earthnut.dev"
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "registry": "https://registry.npmjs.org/"
46
52
  },
47
53
  "browserslist": [
48
- "node>=18.0.0"
54
+ "last 2"
49
55
  ],
50
56
  "engines": {
51
57
  "node": ">=18.0.0"
52
- },
53
- "keywords": [
54
- "log",
55
- "qqi",
56
- "earthnut"
57
- ],
58
- "homepage": "https://earthnut.dev/npm/qqi/log",
59
- "bugs": {
60
- "url": "https://github.com/earthnutDev/qqi/issues",
61
- "email": "earthnut.dev@outlook.com"
62
58
  }
63
59
  }
package/index.cjs DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- var index = require('./src/index.cjs');
4
-
5
-
6
-
7
- exports.Dog = index.Dog;
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { Dog } from './src';
2
- export type { DevLogType, DevLog } from './src/type';
package/index.mjs DELETED
@@ -1 +0,0 @@
1
- export { Dog } from './src/index.mjs';
package/src/blankCall.cjs DELETED
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- *
5
- * 空函数
6
- *
7
- */
8
- function blankCall(...str) {
9
- }
10
-
11
- exports.blankCall = blankCall;
@@ -1,6 +0,0 @@
1
- /**
2
- *
3
- * 空函数
4
- *
5
- */
6
- export declare function blankCall(...str: unknown[]): void;
package/src/blankCall.mjs DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- *
3
- * 空函数
4
- *
5
- */
6
- function blankCall(...str) {
7
- }
8
-
9
- export { blankCall };
package/src/index.cjs DELETED
@@ -1,106 +0,0 @@
1
- 'use strict';
2
-
3
- var aJsTools = require('a-js-tools');
4
- var setType = require('./setType.cjs');
5
- var blankCall = require('./blankCall.cjs');
6
- var managePrint = require('./managePrint.cjs');
7
- var aTypeOfJs = require('a-type-of-js');
8
- var platform = require('./platform.cjs');
9
- var _static = require('@color-pen/static');
10
-
11
- /**
12
- *
13
- * 创建 dev log 工厂函数
14
- *
15
- * @param options - 配置项
16
- * @returns - dev log 工厂函数
17
- *
18
- *
19
- */
20
- function Dog(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;
37
- // 处理 name
38
- name = name.trim().replace(/\s+/g, '_');
39
- /** 当前获取环境值 */
40
- const _env = (platform.platform === 'node' &&
41
- (process.env[name.toUpperCase().concat('_DEV')] ??
42
- process.env[name.toLowerCase().concat('_dev')])) ||
43
- false;
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;
47
- /// 原始的调用方法,在 type 值变化时会触发该值的更替
48
- // 私有方法 error
49
- const _privateFunc = {
50
- error: blankCall.blankCall,
51
- warn: blankCall.blankCall,
52
- info: blankCall.blankCall,
53
- };
54
- managePrint.managePrint(type, _privateFunc, name);
55
- /** 本体方法 */
56
- const dog = (...str) => {
57
- Reflect.apply(_privateFunc.info, this, str);
58
- };
59
- // 设置 prototype
60
- Object.setPrototypeOf(dog, this);
61
- // 设置属性和方法
62
- Object.defineProperties(this, {
63
- type: {
64
- get() {
65
- return type || false;
66
- },
67
- set(value) {
68
- const new_type = setType.setType(value);
69
- if (new_type !== type) {
70
- type = new_type;
71
- managePrint.managePrint(type, _privateFunc, name);
72
- }
73
- },
74
- },
75
- error: {
76
- value: (...str) => Reflect.apply(_privateFunc.error, this, str),
77
- configurable: false,
78
- enumerable: false,
79
- writable: false,
80
- },
81
- warn: {
82
- value: (...str) => Reflect.apply(_privateFunc.warn, this, str),
83
- configurable: false,
84
- enumerable: false,
85
- writable: false,
86
- },
87
- });
88
- return dog;
89
- }
90
- Dog.prototype.clear = () => {
91
- if (platform.platform === 'browser') {
92
- console.clear();
93
- }
94
- else {
95
- console.log(_static.esc.concat('c'));
96
- }
97
- };
98
- /**
99
- *
100
- * @param options 配置项
101
- * @returns 函数对象
102
- *
103
- */
104
- const DogConstructor = aJsTools.createConstructor(Dog);
105
-
106
- exports.Dog = DogConstructor;