@qqi/log 1.1.1 → 1.1.3

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.
Files changed (3) hide show
  1. package/cjs/core.js +33 -17
  2. package/es/core.js +34 -18
  3. package/package.json +1 -1
package/cjs/core.js CHANGED
@@ -18,7 +18,7 @@ var DogConstructor = aJsTools.createConstructor(Dog);
18
18
  * @returns - dev log 工厂函数
19
19
  */
20
20
  function Dog(options) {
21
- var _this = this;
21
+ var _this_1 = this;
22
22
  var _p = util.parseOption(options);
23
23
  this.name = _p.name || aJsTools.getRandomString(12);
24
24
  this.fold = Boolean(_p.fold);
@@ -61,28 +61,30 @@ function Dog(options) {
61
61
  ? colorPen.bgBlackPen.red
62
62
  : colorPen.bgBrightYellowPen.brightGreen)(startStr);
63
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) ;
64
+ if (_this_1.fold && mark) {
65
+ if (mark === _this_1.mark) ;
66
66
  else {
67
- if (_this.mark) {
67
+ if (_this_1.mark) {
68
68
  console.groupEnd();
69
69
  }
70
70
  console.groupCollapsed(mark);
71
71
  }
72
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(' 列'));
73
+ _this_1.mark = mark;
74
+ var msg = "".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
+ return colorPen.colorText(msg);
75
76
  }
76
77
  };
77
78
  this.info = function () {
78
- var msg = [];
79
+ var arg = [];
79
80
  for (var _i = 0; _i < arguments.length; _i++) {
80
- msg[_i] = arguments[_i];
81
+ arg[_i] = arguments[_i];
81
82
  }
82
- if (_this.type === 'all' || _this.type === 'info' || _this.type === true) {
83
+ if (_this_1.type === 'all' || _this_1.type === 'info' || _this_1.type === true) {
83
84
  var _prefix = prefix('info');
84
- msg.unshift(_prefix);
85
- console.log.apply(console, msg);
85
+ console.log.apply(console, _prefix);
86
+ console.log.apply(console, arg);
87
+ // console.log.apply(console, arg);
86
88
  }
87
89
  };
88
90
  /**
@@ -93,9 +95,9 @@ function Dog(options) {
93
95
  for (var _i = 0; _i < arguments.length; _i++) {
94
96
  msg[_i] = arguments[_i];
95
97
  }
96
- if (_this.type === 'all' || _this.type === 'warn' || _this.type === true) {
98
+ if (_this_1.type === 'all' || _this_1.type === 'warn' || _this_1.type === true) {
97
99
  var _prefix = prefix('warn');
98
- msg.unshift(_prefix);
100
+ console.log.apply(console, _prefix);
99
101
  console.warn.apply(console, msg);
100
102
  }
101
103
  };
@@ -108,9 +110,9 @@ function Dog(options) {
108
110
  for (var _i = 0; _i < arguments.length; _i++) {
109
111
  msg[_i] = arguments[_i];
110
112
  }
111
- if (_this.type === 'all' || _this.type === 'error' || _this.type === true) {
113
+ if (_this_1.type === 'all' || _this_1.type === 'error' || _this_1.type === true) {
112
114
  var _prefix = prefix('error');
113
- msg.unshift(_prefix);
115
+ console.log.apply(console, _prefix);
114
116
  console.error.apply(console, msg);
115
117
  }
116
118
  };
@@ -123,11 +125,25 @@ function Dog(options) {
123
125
  for (var _i = 0; _i < arguments.length; _i++) {
124
126
  str[_i] = arguments[_i];
125
127
  }
126
- _this.info(str);
128
+ _this_1.info.apply(_this_1, str);
127
129
  };
128
130
  // 设置 prototype
129
131
  Object.setPrototypeOf(dog, this);
130
- return dog;
132
+ var _this = this;
133
+ return new Proxy(dog, {
134
+ get: function (target, p, receiver) {
135
+ if (p === 'apply') {
136
+ return target;
137
+ }
138
+ else {
139
+ return Reflect.get(target, p, receiver);
140
+ }
141
+ },
142
+ set: function (_target, p, newValue) {
143
+ Reflect.set(_this, p, newValue); // 将要设置的值映射到 this 上而不是自身
144
+ return true;
145
+ },
146
+ });
131
147
  }
132
148
  /** 原型上添加 clear 方法 */
133
149
  Dog.prototype.clear = function () {
package/es/core.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { esc } from '@color-pen/static';
2
2
  import { createConstructor, getRandomString } from 'a-js-tools';
3
- import { bgCyanPen, bgBlackPen, bgBrightYellowPen } from 'color-pen';
3
+ import { bgCyanPen, bgBlackPen, bgBrightYellowPen, colorText } from 'color-pen';
4
4
  import { parseOption, getEnv, platform, setType } from './util.js';
5
5
 
6
6
  /**
@@ -16,7 +16,7 @@ var DogConstructor = createConstructor(Dog);
16
16
  * @returns - dev log 工厂函数
17
17
  */
18
18
  function Dog(options) {
19
- var _this = this;
19
+ var _this_1 = this;
20
20
  var _p = parseOption(options);
21
21
  this.name = _p.name || getRandomString(12);
22
22
  this.fold = Boolean(_p.fold);
@@ -59,28 +59,30 @@ function Dog(options) {
59
59
  ? bgBlackPen.red
60
60
  : bgBrightYellowPen.brightGreen)(startStr);
61
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) ;
62
+ if (_this_1.fold && mark) {
63
+ if (mark === _this_1.mark) ;
64
64
  else {
65
- if (_this.mark) {
65
+ if (_this_1.mark) {
66
66
  console.groupEnd();
67
67
  }
68
68
  console.groupCollapsed(mark);
69
69
  }
70
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(' 列'));
71
+ _this_1.mark = mark;
72
+ var msg = "".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
+ return colorText(msg);
73
74
  }
74
75
  };
75
76
  this.info = function () {
76
- var msg = [];
77
+ var arg = [];
77
78
  for (var _i = 0; _i < arguments.length; _i++) {
78
- msg[_i] = arguments[_i];
79
+ arg[_i] = arguments[_i];
79
80
  }
80
- if (_this.type === 'all' || _this.type === 'info' || _this.type === true) {
81
+ if (_this_1.type === 'all' || _this_1.type === 'info' || _this_1.type === true) {
81
82
  var _prefix = prefix('info');
82
- msg.unshift(_prefix);
83
- console.log.apply(console, msg);
83
+ console.log.apply(console, _prefix);
84
+ console.log.apply(console, arg);
85
+ // console.log.apply(console, arg);
84
86
  }
85
87
  };
86
88
  /**
@@ -91,9 +93,9 @@ function Dog(options) {
91
93
  for (var _i = 0; _i < arguments.length; _i++) {
92
94
  msg[_i] = arguments[_i];
93
95
  }
94
- if (_this.type === 'all' || _this.type === 'warn' || _this.type === true) {
96
+ if (_this_1.type === 'all' || _this_1.type === 'warn' || _this_1.type === true) {
95
97
  var _prefix = prefix('warn');
96
- msg.unshift(_prefix);
98
+ console.log.apply(console, _prefix);
97
99
  console.warn.apply(console, msg);
98
100
  }
99
101
  };
@@ -106,9 +108,9 @@ function Dog(options) {
106
108
  for (var _i = 0; _i < arguments.length; _i++) {
107
109
  msg[_i] = arguments[_i];
108
110
  }
109
- if (_this.type === 'all' || _this.type === 'error' || _this.type === true) {
111
+ if (_this_1.type === 'all' || _this_1.type === 'error' || _this_1.type === true) {
110
112
  var _prefix = prefix('error');
111
- msg.unshift(_prefix);
113
+ console.log.apply(console, _prefix);
112
114
  console.error.apply(console, msg);
113
115
  }
114
116
  };
@@ -121,11 +123,25 @@ function Dog(options) {
121
123
  for (var _i = 0; _i < arguments.length; _i++) {
122
124
  str[_i] = arguments[_i];
123
125
  }
124
- _this.info(str);
126
+ _this_1.info.apply(_this_1, str);
125
127
  };
126
128
  // 设置 prototype
127
129
  Object.setPrototypeOf(dog, this);
128
- return dog;
130
+ var _this = this;
131
+ return new Proxy(dog, {
132
+ get: function (target, p, receiver) {
133
+ if (p === 'apply') {
134
+ return target;
135
+ }
136
+ else {
137
+ return Reflect.get(target, p, receiver);
138
+ }
139
+ },
140
+ set: function (_target, p, newValue) {
141
+ Reflect.set(_this, p, newValue); // 将要设置的值映射到 this 上而不是自身
142
+ return true;
143
+ },
144
+ });
129
145
  }
130
146
  /** 原型上添加 clear 方法 */
131
147
  Dog.prototype.clear = function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "name": "@qqi/log",
5
5
  "main": "cjs/index.js",
6
6
  "module": "es/index.js",