@vvi/log 1.1.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,59 @@
1
+ # 更新日志 📔
2
+
3
+ ## 1.1.5 (2026-6-14)
4
+
5
+ - 维护导出信息
6
+
7
+ ## 1.1.4 (2026-2-3)
8
+
9
+ - 修复已知问题,该问题造成解析参数错误
10
+
11
+ ## 1.1.3 (2026-1-28)
12
+
13
+ - 修复已知问题
14
+
15
+ ## 1.1.2 (2026-1-28)
16
+
17
+ - 修复已知问题
18
+
19
+ ## 1.1.1 (2026-1-28)
20
+
21
+ - 不知道为什么使用时没有摇树,再试试
22
+
23
+ ## 1.1.0 (2026-1-28)
24
+
25
+ - 添加配置项 `fold` 可在打印时将部分信息进行折叠(浏览器控制台)、缩进(终端)
26
+
27
+ ## v1.0.0 (2025-12-27)
28
+
29
+ - 维护依赖
30
+
31
+ ## v0.1.2-rc.0 (2025-8-4)
32
+
33
+ 该版本不发布更新
34
+
35
+ - 在 webpack 为打包的环境下,会将 `dog(...[1, 2, 3])` 这种写法转化为 `dog.apply(void 0, _toConsumableArray([1 ,2 ,3]))` 而由于原型链尽毁不复,只能单独设置(现通过更新上游的 [a-js-tools](https://www.npmjs.com/package/a-js-tools) 解决所有的问题)
36
+
37
+ ## v0.1.1 (2025-7-27)
38
+
39
+ - 整理文档
40
+
41
+ ## v0.1.0 (2025-7-18)
42
+
43
+ - no 临时工
44
+
45
+ ## v0.0.3-alpha.0 (2025-7-18)
46
+
47
+ - 修改导出的 Dog 类型丢失
48
+
49
+ ## v0.0.2 (2025-6-29)
50
+
51
+ - 闹笑话了不是,局部变量与外部变量同名导致变量数值冲突,而导致 type 值无法赋新值
52
+
53
+ ## v0.0.1 (2025-6-21)
54
+
55
+ - 非 node 环境亦通过 type 来控制其是否打印,这样就可以在某一个方法执行前后进行控制打印短路
56
+
57
+ ## v0.0.0 (2025-6-20)
58
+
59
+ - 创建项目
package/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ # MIT License
2
+
3
+ Copyright ©️ <2025> <Mr.MudBean>
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @vvi/log
2
+
3
+ [![version](<https://img.shields.io/npm/v/@vvi/log.svg?logo=@mudbean/npm&logoColor=rgb(0,0,0)&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/@vvi/log) [![issues 提交](<https://img.shields.io/badge/issues-提交-rgb(255,0,63)?logo=github>)](https://github.com/MrMudBean/log/issues)
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install --save @vvi/log
9
+ ```
10
+
11
+ ## 使用 Dog
12
+
13
+ ### 创建全局的 `dog` (dev log 的缩写,天才第一步,起名要认真) 对象
14
+
15
+ ```ts
16
+ /// 这里假设以 `a node tools` 为 `name` 的值
17
+ export const dog = new Dog({ name: 'a node tools' });
18
+ ```
19
+
20
+ ### 在需要打印日志的地方引入 `dog` 对象
21
+
22
+ ```ts
23
+ import { dog } from './dog';
24
+
25
+ dog('你好'); // 该值是否打印还依赖于环境变量中有没有配置 `dev_log_dev` 的值
26
+ ```
27
+
28
+ ### 启用配置
29
+
30
+ ```bash
31
+ # 配置 name 为 'a node tools',则使用 `a_node_tools_dev` 或 `A_NODE_TOOLS_DEV` 来启动
32
+ a_node_tools_dev=true npm run dev
33
+ ```
34
+
35
+ ### 折叠同名方法打印消息
36
+
37
+ 使用 `fold` 参数 :
38
+
39
+ ```js
40
+ import { Dog } from '@vvi/log';
41
+
42
+ const dog = Dog();
43
+ ```
44
+
45
+ ## 状态
46
+
47
+ 此软件包是 `@mudbean` 生态系统的一部分。
48
+ 它使用严格的 TypeScript 编写,并通过 Rollup 构建进行验证。
49
+ 虽然单元测试较少,但 API 稳定,并在生产环境中大量使用。
package/cjs/core.js ADDED
@@ -0,0 +1,140 @@
1
+ 'use strict';
2
+
3
+ var pen = require('@vvi/pen');
4
+ var penStatic = require('@vvi/pen-static');
5
+ var utils = require('@vvi/utils');
6
+ var util = require('./util.js');
7
+
8
+ /**
9
+ *
10
+ * @param options 配置项
11
+ * @returns 函数对象
12
+ *
13
+ */
14
+ const DogConstructor = utils.createConstructor(Dog);
15
+ /**
16
+ * # 创建 dev log 工厂函数
17
+ * @param options - 配置项
18
+ * @returns - dev log 工厂函数
19
+ */
20
+ function Dog(options) {
21
+ const _p = util.parseOption(options);
22
+ this.name = _p.name || utils.getRandomString(12);
23
+ this.fold = Boolean(_p.fold);
24
+ const env = util.getEnv(this.name);
25
+ let type = _p.type || false;
26
+ this.mark = '';
27
+ /** 默认 node 环境以获取到的环境值为准,而非 node 环境默认开启,并通过自定义的 @qqi/babel-plugin-remove-dog-calls 来进行过滤正式环境(环境值需要自定义) */
28
+ this.type = util.platform === 'node' ? util.setType(env ?? type) : true;
29
+ /**
30
+ * ## 解析 error
31
+ * @param type
32
+ */
33
+ const prefix = (type) => {
34
+ try {
35
+ throw new Error();
36
+ }
37
+ catch (error) {
38
+ const parseErrorResult = (error.stack?.split('\n') || []).map(item => {
39
+ const reg = /at\s(.*)\s\((.*):(\d*):(\d*)\)/;
40
+ const 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
+ const result = parseErrorResult.filter(e => e.name !== '' && e.path !== undefined);
54
+ const res = result[3] ?? result[2] ?? result[1] ?? result[0];
55
+ const startStr = ` ${type === 'info' ? '💡' : type === 'error' ? '❌' : '⚠️ '} ${new Date().toLocaleString()} `;
56
+ const printStartPenStr = (type === 'info'
57
+ ? pen.bgCyanPen.brightWhite
58
+ : type === 'error'
59
+ ? pen.bgBlackPen.red
60
+ : pen.bgBrightYellowPen.brightGreen)(startStr);
61
+ const mark = res?.name ?? '';
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
+ const msg = `${printStartPenStr} ${mark} ${res?.line?.concat(' 行')} ${res?.column?.concat(' 列')}`;
73
+ return pen.colorText(msg);
74
+ }
75
+ };
76
+ this.info = (...arg) => {
77
+ if (this.type === 'all' || this.type === 'info' || this.type === true) {
78
+ const _prefix = prefix('info');
79
+ console.log(..._prefix);
80
+ console.log(...arg);
81
+ // console.log.apply(console, arg);
82
+ }
83
+ };
84
+ /**
85
+ * @param msg
86
+ */
87
+ this.warn = (...msg) => {
88
+ if (this.type === 'all' || this.type === 'warn' || this.type === true) {
89
+ const _prefix = prefix('warn');
90
+ console.log(..._prefix);
91
+ console.warn.apply(console, msg);
92
+ }
93
+ };
94
+ /**
95
+ *
96
+ * @param msg
97
+ */
98
+ this.error = (...msg) => {
99
+ if (this.type === 'all' || this.type === 'error' || this.type === true) {
100
+ const _prefix = prefix('error');
101
+ console.log(..._prefix);
102
+ console.error.apply(console, msg);
103
+ }
104
+ };
105
+ /**
106
+ * 本体方法
107
+ * @param str
108
+ */
109
+ const dog = (...str) => {
110
+ this.info(...str);
111
+ };
112
+ // 设置 prototype
113
+ Object.setPrototypeOf(dog, this);
114
+ const _this = this;
115
+ return new Proxy(dog, {
116
+ get(target, p, receiver) {
117
+ if (p === 'apply') {
118
+ return target;
119
+ }
120
+ else {
121
+ return Reflect.get(target, p, receiver);
122
+ }
123
+ },
124
+ set(_target, p, newValue) {
125
+ Reflect.set(_this, p, newValue); // 将要设置的值映射到 this 上而不是自身
126
+ return true;
127
+ },
128
+ });
129
+ }
130
+ /** 原型上添加 clear 方法 */
131
+ Dog.prototype.clear = () => {
132
+ if (util.platform === 'browser') {
133
+ console.clear();
134
+ }
135
+ else {
136
+ console.log(penStatic.esc.concat('c'));
137
+ }
138
+ };
139
+
140
+ exports.Dog = DogConstructor;
package/cjs/index.js ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var core = require('./core.js');
4
+ var virtualDog = require('./virtual-dog.js');
5
+
6
+
7
+
8
+ exports.Dog = core.Dog;
9
+ exports.DogVirtual = virtualDog.DogVirtual;
package/cjs/util.js ADDED
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ var is = require('@vvi/is');
4
+ var utils = require('@vvi/utils');
5
+
6
+ /**
7
+ * @packageDocumentation
8
+ * @module @vvi/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-06-15 20:37
17
+ */
18
+ const 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
+ const result = {
32
+ name: utils.getRandomString(10),
33
+ type: false,
34
+ fold: false,
35
+ };
36
+ if (is.isUndefined(options))
37
+ return result;
38
+ if (is.isBoolean(options)) {
39
+ result.type = options;
40
+ return result;
41
+ }
42
+ if (is.isString(options)) {
43
+ // 处理 name
44
+ result.name = options.trim().replace(/\s+/g, '_');
45
+ return result;
46
+ }
47
+ if (is.isString(options.name)) {
48
+ options.name = options.name.trim().replace(/\s+/g, '_');
49
+ }
50
+ options.fold = Boolean(options.fold);
51
+ return options;
52
+ }
53
+ /**
54
+ * 获取当前的环境变量
55
+ * @param name
56
+ */
57
+ function getEnv(name = utils.getRandomString(10)) {
58
+ /** 当前获取环境值 */
59
+ let _env = false;
60
+ if (platform === 'node' && globalThis?.process?.env) {
61
+ const processEnv = process.env;
62
+ _env =
63
+ processEnv[name.toUpperCase().concat('_DEV')] ||
64
+ processEnv[name.toLowerCase().concat('_dev')] ||
65
+ false;
66
+ }
67
+ const env = _env === 'false' ? false : _env === 'true' ? true : _env;
68
+ return env;
69
+ }
70
+ const platform = utils.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
+ exports.getEnv = getEnv;
82
+ exports.parseOption = parseOption;
83
+ exports.platform = platform;
84
+ exports.setType = setType;
85
+ exports.typeList = typeList;
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var utils = require('@vvi/utils');
4
+
5
+ /**
6
+ * @packageDocumentation
7
+ * @module @vvi/log/virtual-dog
8
+ * @file virtual-dog.ts
9
+ * @description _
10
+ * @author MrMudBean <Mr.MudBean@outlook.com>
11
+ * @license MIT
12
+ * @copyright 2026 ©️ MrMudBean
13
+ * @since 2026-01-28 04:52
14
+ * @version 1.1.0
15
+ * @lastModified 2026-06-15 20:37
16
+ */
17
+ /**
18
+ *
19
+ */
20
+ function DogVirtualImt() {
21
+ /**
22
+ * 模拟类的构建
23
+ * @param _arg
24
+ */
25
+ const _dev = (..._arg) => { };
26
+ Object.setPrototypeOf(_dev, this);
27
+ Object.defineProperties(this, {
28
+ info: {
29
+ value: (..._) => { },
30
+ configurable: false,
31
+ writable: false,
32
+ },
33
+ warn: {
34
+ value: (..._) => { },
35
+ configurable: false,
36
+ writable: false,
37
+ },
38
+ error: {
39
+ value: (..._) => { },
40
+ configurable: false,
41
+ writable: false,
42
+ },
43
+ type: {
44
+ get() {
45
+ return false;
46
+ },
47
+ set(_) { },
48
+ },
49
+ });
50
+ return _dev;
51
+ }
52
+ DogVirtualImt.prototype.clear = console.clear;
53
+ /** 虚拟狗,没有实现不打印 */
54
+ const DogVirtualConstructor = utils.createConstructor(DogVirtualImt);
55
+
56
+ exports.DogVirtual = DogVirtualConstructor;
package/es/core.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { DevLog, DogOptions } from './type';
2
+ /**
3
+ *
4
+ * @param options 配置项
5
+ * @returns 函数对象
6
+ *
7
+ */
8
+ declare const DogConstructor: import("@vvi/utils").CreateConstructor<DevLog, [options?: DogOptions | undefined]>;
9
+ export { DogConstructor as Dog };
package/es/core.js ADDED
@@ -0,0 +1,138 @@
1
+ import { bgCyanPen, bgBlackPen, bgBrightYellowPen, colorText } from '@vvi/pen';
2
+ import { esc } from '@vvi/pen-static';
3
+ import { createConstructor, getRandomString } from '@vvi/utils';
4
+ import { parseOption, getEnv, platform, setType } from './util.js';
5
+
6
+ /**
7
+ *
8
+ * @param options 配置项
9
+ * @returns 函数对象
10
+ *
11
+ */
12
+ const DogConstructor = createConstructor(Dog);
13
+ /**
14
+ * # 创建 dev log 工厂函数
15
+ * @param options - 配置项
16
+ * @returns - dev log 工厂函数
17
+ */
18
+ function Dog(options) {
19
+ const _p = parseOption(options);
20
+ this.name = _p.name || getRandomString(12);
21
+ this.fold = Boolean(_p.fold);
22
+ const env = getEnv(this.name);
23
+ let type = _p.type || false;
24
+ this.mark = '';
25
+ /** 默认 node 环境以获取到的环境值为准,而非 node 环境默认开启,并通过自定义的 @qqi/babel-plugin-remove-dog-calls 来进行过滤正式环境(环境值需要自定义) */
26
+ this.type = platform === 'node' ? setType(env ?? type) : true;
27
+ /**
28
+ * ## 解析 error
29
+ * @param type
30
+ */
31
+ const prefix = (type) => {
32
+ try {
33
+ throw new Error();
34
+ }
35
+ catch (error) {
36
+ const parseErrorResult = (error.stack?.split('\n') || []).map(item => {
37
+ const reg = /at\s(.*)\s\((.*):(\d*):(\d*)\)/;
38
+ const res = reg.exec(item);
39
+ if (res) {
40
+ return {
41
+ name: res[1],
42
+ path: res[2],
43
+ line: res[3],
44
+ column: res[4],
45
+ };
46
+ }
47
+ return {
48
+ name: '',
49
+ };
50
+ });
51
+ const result = parseErrorResult.filter(e => e.name !== '' && e.path !== undefined);
52
+ const res = result[3] ?? result[2] ?? result[1] ?? result[0];
53
+ const startStr = ` ${type === 'info' ? '💡' : type === 'error' ? '❌' : '⚠️ '} ${new Date().toLocaleString()} `;
54
+ const printStartPenStr = (type === 'info'
55
+ ? bgCyanPen.brightWhite
56
+ : type === 'error'
57
+ ? bgBlackPen.red
58
+ : bgBrightYellowPen.brightGreen)(startStr);
59
+ const mark = res?.name ?? '';
60
+ if (this.fold && mark) {
61
+ if (mark === this.mark) ;
62
+ else {
63
+ if (this.mark) {
64
+ console.groupEnd();
65
+ }
66
+ console.groupCollapsed(mark);
67
+ }
68
+ }
69
+ this.mark = mark;
70
+ const msg = `${printStartPenStr} ${mark} ${res?.line?.concat(' 行')} ${res?.column?.concat(' 列')}`;
71
+ return colorText(msg);
72
+ }
73
+ };
74
+ this.info = (...arg) => {
75
+ if (this.type === 'all' || this.type === 'info' || this.type === true) {
76
+ const _prefix = prefix('info');
77
+ console.log(..._prefix);
78
+ console.log(...arg);
79
+ // console.log.apply(console, arg);
80
+ }
81
+ };
82
+ /**
83
+ * @param msg
84
+ */
85
+ this.warn = (...msg) => {
86
+ if (this.type === 'all' || this.type === 'warn' || this.type === true) {
87
+ const _prefix = prefix('warn');
88
+ console.log(..._prefix);
89
+ console.warn.apply(console, msg);
90
+ }
91
+ };
92
+ /**
93
+ *
94
+ * @param msg
95
+ */
96
+ this.error = (...msg) => {
97
+ if (this.type === 'all' || this.type === 'error' || this.type === true) {
98
+ const _prefix = prefix('error');
99
+ console.log(..._prefix);
100
+ console.error.apply(console, msg);
101
+ }
102
+ };
103
+ /**
104
+ * 本体方法
105
+ * @param str
106
+ */
107
+ const dog = (...str) => {
108
+ this.info(...str);
109
+ };
110
+ // 设置 prototype
111
+ Object.setPrototypeOf(dog, this);
112
+ const _this = this;
113
+ return new Proxy(dog, {
114
+ get(target, p, receiver) {
115
+ if (p === 'apply') {
116
+ return target;
117
+ }
118
+ else {
119
+ return Reflect.get(target, p, receiver);
120
+ }
121
+ },
122
+ set(_target, p, newValue) {
123
+ Reflect.set(_this, p, newValue); // 将要设置的值映射到 this 上而不是自身
124
+ return true;
125
+ },
126
+ });
127
+ }
128
+ /** 原型上添加 clear 方法 */
129
+ Dog.prototype.clear = () => {
130
+ if (platform === 'browser') {
131
+ console.clear();
132
+ }
133
+ else {
134
+ console.log(esc.concat('c'));
135
+ }
136
+ };
137
+
138
+ export { DogConstructor as Dog };
package/es/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module @vvi/log/index
4
+ * @file index.ts
5
+ * @description _
6
+ * @author MrMudBean <Mr.MudBean@outlook.com>
7
+ * @license MIT
8
+ * @copyright 2026 ©️ MrMudBean
9
+ * @since 2026-01-28 04:52
10
+ * @version 1.1.0
11
+ * @lastModified 2026-06-15 20:37
12
+ */
13
+ export { Dog } from './core';
14
+ export { DogVirtual } from './virtual-dog';
15
+ export type { DevLogType, DevLog } from './type';
package/es/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Dog } from './core.js';
2
+ export { DogVirtual } from './virtual-dog.js';
package/es/type.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ export type DevLogType = boolean | 'info' | 'error' | 'all' | 'warn';
2
+ export type DevLog = {
3
+ /** 打印信息本当作为 info 信息,在 type 为 `false`、`error`、`warn` 时不打印 */
4
+ (...str: unknown[]): void;
5
+ /** 当打印的版本为错误信息,在 type 为 `false`、`error`、`warn` 时不打印 */
6
+ info: (...str: unknown[]) => void;
7
+ /** 当打印的版本为错误信息,在 type 为 `false`、`info`、`warn` 时不打印 */
8
+ error: (...str: unknown[]) => void;
9
+ /** 当打印的版本为警示信息,在 type 为 `false`、`info`、`error` 时不打印 */
10
+ warn: (...str: unknown[]) => void;
11
+ /** node 平台执行依据 */
12
+ name: string;
13
+ /** 同名(方法)折叠 */
14
+ fold: boolean;
15
+ /** 开启打印的类型 */
16
+ type: DevLogType;
17
+ /** 当前标记的名 */
18
+ mark: string;
19
+ /** 清除控制台 */
20
+ clear: () => void;
21
+ };
22
+ export type platform = 'node' | 'browser';
23
+ export interface PrivateFunc {
24
+ error: (...str: unknown[]) => void;
25
+ warn: (...str: unknown[]) => void;
26
+ info: (...str: unknown[]) => void;
27
+ }
28
+ export type DogOptions = {
29
+ /**
30
+ * ## 类型
31
+ * 但是该值将被传入的系统参数覆盖
32
+ */
33
+ type?: DevLogType;
34
+ /** 该值将以 name_dev 的形式配置允许打印 */
35
+ name?: string;
36
+ /** 同名文件打印消息是否折叠(控制台效果不明显) */
37
+ fold?: boolean;
38
+ } | string | boolean;
package/es/util.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module @vvi/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-06-15 20:37
12
+ */
13
+ import { DogOptions, type DevLogType } from './type';
14
+ export declare const typeList: DevLogType[];
15
+ /**
16
+ * ## 解析参数
17
+ * @param options
18
+ */
19
+ export declare function parseOption(options?: DogOptions): {
20
+ name?: string;
21
+ type?: DevLogType;
22
+ fold?: boolean;
23
+ };
24
+ /**
25
+ * 获取当前的环境变量
26
+ * @param name
27
+ */
28
+ export declare function getEnv(name?: string): DevLogType;
29
+ export declare const platform: string;
30
+ /**
31
+ * 设置 type 的类型
32
+ * @param type 新的类型
33
+ */
34
+ export declare function setType(type: DevLogType): DevLogType;
package/es/util.js ADDED
@@ -0,0 +1,79 @@
1
+ import { isUndefined, isBoolean, isString } from '@vvi/is';
2
+ import { isNode, getRandomString } from '@vvi/utils';
3
+
4
+ /**
5
+ * @packageDocumentation
6
+ * @module @vvi/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-06-15 20:37
15
+ */
16
+ const 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
+ const 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
+ options.name = options.name.trim().replace(/\s+/g, '_');
47
+ }
48
+ options.fold = Boolean(options.fold);
49
+ return options;
50
+ }
51
+ /**
52
+ * 获取当前的环境变量
53
+ * @param name
54
+ */
55
+ function getEnv(name = getRandomString(10)) {
56
+ /** 当前获取环境值 */
57
+ let _env = false;
58
+ if (platform === 'node' && globalThis?.process?.env) {
59
+ const processEnv = process.env;
60
+ _env =
61
+ processEnv[name.toUpperCase().concat('_DEV')] ||
62
+ processEnv[name.toLowerCase().concat('_dev')] ||
63
+ false;
64
+ }
65
+ const env = _env === 'false' ? false : _env === 'true' ? true : _env;
66
+ return env;
67
+ }
68
+ const platform = isNode() ? 'node' : 'browser';
69
+ /**
70
+ * 设置 type 的类型
71
+ * @param type 新的类型
72
+ */
73
+ function setType(type) {
74
+ if (typeList.includes(type))
75
+ return type;
76
+ return false;
77
+ }
78
+
79
+ export { getEnv, parseOption, platform, setType, typeList };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module @vvi/log/virtual-dog
4
+ * @file virtual-dog.ts
5
+ * @description _
6
+ * @author MrMudBean <Mr.MudBean@outlook.com>
7
+ * @license MIT
8
+ * @copyright 2026 ©️ MrMudBean
9
+ * @since 2026-01-28 04:52
10
+ * @version 1.1.0
11
+ * @lastModified 2026-06-15 20:37
12
+ */
13
+ import { DevLog } from './type';
14
+ /** 虚拟狗,没有实现不打印 */
15
+ declare const DogVirtualConstructor: import("@vvi/utils").CreateConstructor<DevLog, []>;
16
+ export { DogVirtualConstructor as DogVirtual };
@@ -0,0 +1,54 @@
1
+ import { createConstructor } from '@vvi/utils';
2
+
3
+ /**
4
+ * @packageDocumentation
5
+ * @module @vvi/log/virtual-dog
6
+ * @file virtual-dog.ts
7
+ * @description _
8
+ * @author MrMudBean <Mr.MudBean@outlook.com>
9
+ * @license MIT
10
+ * @copyright 2026 ©️ MrMudBean
11
+ * @since 2026-01-28 04:52
12
+ * @version 1.1.0
13
+ * @lastModified 2026-06-15 20:37
14
+ */
15
+ /**
16
+ *
17
+ */
18
+ function DogVirtualImt() {
19
+ /**
20
+ * 模拟类的构建
21
+ * @param _arg
22
+ */
23
+ const _dev = (..._arg) => { };
24
+ Object.setPrototypeOf(_dev, this);
25
+ Object.defineProperties(this, {
26
+ info: {
27
+ value: (..._) => { },
28
+ configurable: false,
29
+ writable: false,
30
+ },
31
+ warn: {
32
+ value: (..._) => { },
33
+ configurable: false,
34
+ writable: false,
35
+ },
36
+ error: {
37
+ value: (..._) => { },
38
+ configurable: false,
39
+ writable: false,
40
+ },
41
+ type: {
42
+ get() {
43
+ return false;
44
+ },
45
+ set(_) { },
46
+ },
47
+ });
48
+ return _dev;
49
+ }
50
+ DogVirtualImt.prototype.clear = console.clear;
51
+ /** 虚拟狗,没有实现不打印 */
52
+ const DogVirtualConstructor = createConstructor(DogVirtualImt);
53
+
54
+ export { DogVirtualConstructor as DogVirtual };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@vvi/log",
3
+ "version": "1.1.5",
4
+ "type": "module",
5
+ "main": "cjs/index.js",
6
+ "module": "es/index.js",
7
+ "types": "es/index.d.ts",
8
+ "author": {
9
+ "name": "泥豆君",
10
+ "email": "Mr.MudBean@outlook.com",
11
+ "url": "https://mudbean.cn"
12
+ },
13
+ "description": "一个简单的 console.log ",
14
+ "sideEffects": false,
15
+ "license": "MIT",
16
+ "files": [
17
+ "cjs",
18
+ "es",
19
+ "LICENSE",
20
+ "README.md",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "default": "./es/index.js",
27
+ "types": "./es/index.d.ts"
28
+ },
29
+ "require": {
30
+ "default": "./cjs/index.js",
31
+ "types": "./es/index.d.ts"
32
+ }
33
+ }
34
+ },
35
+ "keywords": [
36
+ "log",
37
+ "mudbean",
38
+ "vvi"
39
+ ],
40
+ "homepage": "https://npm.lmssee.com/log",
41
+ "dependencies": {
42
+ "@vvi/is": "^2.0.5",
43
+ "@vvi/pen": "^3.0.2",
44
+ "@vvi/pen-static": "^1.1.3",
45
+ "@vvi/utils": "^2.0.6"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/MrMudBean/log/issues",
49
+ "email": "Mr.MudBean@outlook.com"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/MrMudBean/log.git"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public",
57
+ "registry": "https://registry.npmjs.org/"
58
+ },
59
+ "browserslist": [
60
+ "node>=18.0.0"
61
+ ],
62
+ "engines": {
63
+ "node": ">=18.0.0"
64
+ }
65
+ }