@reliverse/relinka 1.1.5 → 1.1.6
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/dist-npm/components/anykey/index.js +77 -57
- package/dist-npm/components/block/block.js +61 -48
- package/dist-npm/components/checkbox/index.js +211 -178
- package/dist-npm/components/confirm/confirm-main.js +122 -85
- package/dist-npm/components/confirm/confirm-three.js +27 -24
- package/dist-npm/components/confirm/index.js +45 -36
- package/dist-npm/components/core/Separator.js +17 -15
- package/dist-npm/components/core/create-prompt.js +124 -101
- package/dist-npm/components/core/errors.js +15 -19
- package/dist-npm/components/core/hook-engine.js +120 -91
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +6 -16
- package/dist-npm/components/core/lines.js +54 -45
- package/dist-npm/components/core/make-theme.js +30 -21
- package/dist-npm/components/core/position.js +23 -27
- package/dist-npm/components/core/promise-polyfill.js +14 -11
- package/dist-npm/components/core/screen-manager.js +74 -59
- package/dist-npm/components/core/theme.js +32 -22
- package/dist-npm/components/core/use-effect.js +15 -9
- package/dist-npm/components/core/use-keypress.js +23 -19
- package/dist-npm/components/core/use-memo.js +16 -10
- package/dist-npm/components/core/use-pagination.js +32 -33
- package/dist-npm/components/core/use-prefix.js +38 -40
- package/dist-npm/components/core/use-ref.js +5 -2
- package/dist-npm/components/core/use-state.js +23 -15
- package/dist-npm/components/core/useKeyPress.js +17 -14
- package/dist-npm/components/core/usePromptState.js +14 -8
- package/dist-npm/components/core/utils.js +16 -7
- package/dist-npm/components/date/date.js +204 -167
- package/dist-npm/components/editor/index.js +92 -71
- package/dist-npm/components/expand/index.js +124 -96
- package/dist-npm/components/figures/index.js +294 -283
- package/dist-npm/components/input/index.js +87 -61
- package/dist-npm/components/input/text-main.js +124 -97
- package/dist-npm/components/input/text.js +28 -24
- package/dist-npm/components/instance/basic.js +25 -17
- package/dist-npm/components/instance/browser.js +18 -14
- package/dist-npm/components/instance/reporter/basic.js +65 -46
- package/dist-npm/components/instance/reporter/browser.js +47 -44
- package/dist-npm/components/instance/reporter/fancy.js +96 -83
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +62 -52
- package/dist-npm/components/mono/monoTwo.js +49 -35
- package/dist-npm/components/multiselect/group-multiselect.js +71 -55
- package/dist-npm/components/multiselect/multi-select-two.js +130 -97
- package/dist-npm/components/multiselect/multi-select.js +49 -43
- package/dist-npm/components/multiselect/multiselect-main.js +146 -120
- package/dist-npm/components/multiselect/num-multi-select.js +130 -97
- package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
- package/dist-npm/components/next-steps/next-steps.js +25 -23
- package/dist-npm/components/number/index.js +112 -78
- package/dist-npm/components/number/number-main.js +2 -95
- package/dist-npm/components/password/index.js +73 -54
- package/dist-npm/components/password/password-main.js +2 -119
- package/dist-npm/components/password/password-three.js +30 -26
- package/dist-npm/components/progressbar/ProgressBar.js +64 -45
- package/dist-npm/components/progressbar/helper.js +40 -33
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +44 -29
- package/dist-npm/components/prompts/index.js +45 -45
- package/dist-npm/components/prompts/prompt.js +260 -211
- package/dist-npm/components/prompts/promptTwo.js +605 -561
- package/dist-npm/components/prompts/relinka.js +295 -237
- package/dist-npm/components/range/range.js +294 -247
- package/dist-npm/components/rawlist/index.js +107 -87
- package/dist-npm/components/results/results.js +37 -31
- package/dist-npm/components/search/index.js +193 -148
- package/dist-npm/components/select/index.js +186 -148
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +5 -124
- package/dist-npm/components/select/select-key.js +25 -24
- package/dist-npm/components/select/select-main.js +133 -109
- package/dist-npm/components/select/select-three.js +36 -32
- package/dist-npm/components/select/select-two.js +87 -94
- package/dist-npm/components/spinner/index.js +136 -107
- package/dist-npm/components/st-end/end.js +26 -34
- package/dist-npm/components/st-end/start.js +15 -29
- package/dist-npm/components/toggle/index.js +137 -113
- package/dist-npm/components/visual/animate/animate.js +10 -53
- package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
- package/dist-npm/mod.js +2 -1
- package/dist-npm/testing/index.js +83 -58
- package/dist-npm/types/general.js +1 -0
- package/dist-npm/types/index.js +3 -2
- package/dist-npm/types/keypress.js +36 -35
- package/dist-npm/types/readline.js +1 -0
- package/dist-npm/types/relinka.js +1 -0
- package/dist-npm/types/utils.js +1 -0
- package/dist-npm/utils/box.js +137 -135
- package/dist-npm/utils/color.js +74 -65
- package/dist-npm/utils/colorize.js +156 -124
- package/dist-npm/utils/component.js +657 -532
- package/dist-npm/utils/constants.js +63 -64
- package/dist-npm/utils/core.js +3 -2
- package/dist-npm/utils/decoder.js +223 -244
- package/dist-npm/utils/error.js +9 -4
- package/dist-npm/utils/errors.js +4 -14
- package/dist-npm/utils/format.js +24 -19
- package/dist-npm/utils/keypress.js +414 -316
- package/dist-npm/utils/log.js +15 -11
- package/dist-npm/utils/mapping.js +52 -45
- package/dist-npm/utils/messages.js +183 -183
- package/dist-npm/utils/platforms.js +20 -16
- package/dist-npm/utils/prompt-tmp.js +286 -235
- package/dist-npm/utils/prompt-two.js +286 -235
- package/dist-npm/utils/readline.js +7 -5
- package/dist-npm/utils/skeleton.js +170 -130
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +58 -44
- package/dist-npm/utils/terminal.js +34 -23
- package/dist-npm/utils/tree.js +41 -30
- package/dist-npm/utils/types.js +1 -0
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +44 -36
- package/package.json +20 -28
|
@@ -1,280 +1,338 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {defu} from 'defu';
|
|
2
|
+
import {LogTypes} from '../../utils/constants.js';
|
|
3
|
+
import {isLogObj} from '../../utils/log.js';
|
|
4
|
+
|
|
5
|
+
const {isArray} = Array;
|
|
6
|
+
const isNumber = (a) => typeof a === 'number';
|
|
7
|
+
const isString = (a) => typeof a === 'string';
|
|
8
|
+
const isFn = (a) => typeof a === 'function';
|
|
9
|
+
const maybeArray = (a) => isArray(a) ? a : [a];
|
|
4
10
|
let paused = false;
|
|
5
11
|
const queue = [];
|
|
12
|
+
|
|
6
13
|
export class Relinka {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
options;
|
|
15
|
+
_lastLog;
|
|
16
|
+
_mockFn;
|
|
10
17
|
constructor(options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const types = options.types || LogTypes;
|
|
19
|
+
|
|
20
|
+
this.options = defu({
|
|
21
|
+
...options,
|
|
22
|
+
defaults: {...options.defaults},
|
|
23
|
+
level: _normalizeLogLevel(options.level, types),
|
|
24
|
+
reporters: options.reporters || [].slice(),
|
|
25
|
+
}, {
|
|
26
|
+
types: LogTypes,
|
|
27
|
+
throttle: 1e3,
|
|
28
|
+
throttleMin: 5,
|
|
29
|
+
formatOptions: {
|
|
30
|
+
date: true,
|
|
31
|
+
colors: false,
|
|
32
|
+
compact: true,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
for (const type in types) {
|
|
36
|
+
const defaults = {
|
|
37
|
+
type,
|
|
38
|
+
...this.options.defaults,
|
|
39
|
+
...types[type],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
this[type] = this._wrapLogFn(defaults);
|
|
43
|
+
this[type].raw = this._wrapLogFn(defaults, true);
|
|
27
44
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...this.options.defaults,
|
|
34
|
-
...types[type]
|
|
35
|
-
};
|
|
36
|
-
this[type] = this._wrapLogFn(defaults);
|
|
37
|
-
this[type].raw = this._wrapLogFn(
|
|
38
|
-
defaults,
|
|
39
|
-
true
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (this.options.mockFn) {
|
|
43
|
-
this.mockTypes();
|
|
45
|
+
if (this.options.mockFn) {
|
|
46
|
+
this.mockTypes();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this._lastLog = {};
|
|
44
50
|
}
|
|
45
|
-
|
|
46
|
-
}
|
|
51
|
+
|
|
47
52
|
get level() {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
return this.options.level;
|
|
54
|
+
}
|
|
55
|
+
|
|
50
56
|
set level(level) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.options.level
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
+
this.options.level = _normalizeLogLevel(level, this.options.types, this.options.level);
|
|
58
|
+
}
|
|
59
|
+
|
|
57
60
|
prompt(message, opts) {
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
if (!this.options.prompt) {
|
|
62
|
+
throw Error('prompt is not supported!');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this.options.prompt(message, opts);
|
|
60
66
|
}
|
|
61
|
-
|
|
62
|
-
}
|
|
67
|
+
|
|
63
68
|
create(options) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
const instance = new Relinka({
|
|
70
|
+
...this.options,
|
|
71
|
+
...options,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (this._mockFn) {
|
|
75
|
+
instance.mockTypes(this._mockFn);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return instance;
|
|
70
79
|
}
|
|
71
|
-
|
|
72
|
-
}
|
|
80
|
+
|
|
73
81
|
withDefaults(defaults) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
return this.create({
|
|
83
|
+
...this.options,
|
|
84
|
+
defaults: {
|
|
85
|
+
...this.options.defaults,
|
|
86
|
+
...defaults,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
82
91
|
withTag(tag) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
return this.withDefaults({
|
|
93
|
+
tag: this.options.defaults.tag ? this.options.defaults.tag + ':' + tag : tag,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
87
97
|
addReporter(reporter) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
this.options.reporters.push(reporter);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
91
102
|
removeReporter(reporter) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
if (reporter) {
|
|
104
|
+
const i = this.options.reporters.indexOf(reporter);
|
|
105
|
+
|
|
106
|
+
if (i >= 0) {
|
|
107
|
+
return this.options.reporters.splice(i, 1);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
this.options.reporters.splice(0);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return this;
|
|
99
114
|
}
|
|
100
|
-
|
|
101
|
-
}
|
|
115
|
+
|
|
102
116
|
setReporters(reporters) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
this.options.reporters = maybeArray(reporters);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
wrapAll() {
|
|
122
|
+
this.wrapConsole();
|
|
123
|
+
this.wrapStd();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
restoreAll() {
|
|
127
|
+
this.restoreConsole();
|
|
128
|
+
this.restoreStd();
|
|
129
|
+
}
|
|
130
|
+
|
|
114
131
|
wrapConsole() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
for (const type in this.options.types) {
|
|
133
|
+
if (!console[`__${type}`]) {
|
|
134
|
+
console[`__${type}`] = console[type];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
console[type] = this[type].raw;
|
|
138
|
+
}
|
|
120
139
|
}
|
|
121
|
-
|
|
140
|
+
|
|
122
141
|
restoreConsole() {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
142
|
+
for (const type in this.options.types) {
|
|
143
|
+
if (console[`__${type}`]) {
|
|
144
|
+
console[type] = console[`__${type}`];
|
|
145
|
+
delete console[`__${type}`];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
128
148
|
}
|
|
129
|
-
|
|
149
|
+
|
|
130
150
|
wrapStd() {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
_wrapStream(stream, type) {
|
|
135
|
-
if (!stream) {
|
|
136
|
-
return;
|
|
151
|
+
this._wrapStream(this.options.stdout, 'log');
|
|
152
|
+
this._wrapStream(this.options.stderr, 'log');
|
|
137
153
|
}
|
|
138
|
-
|
|
139
|
-
|
|
154
|
+
|
|
155
|
+
_wrapStream(stream, type) {
|
|
156
|
+
if (!stream) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!stream.__write) {
|
|
161
|
+
stream.__write = stream.write;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
stream.write = (data) => {
|
|
165
|
+
this[type].raw(String(data).trim());
|
|
166
|
+
};
|
|
140
167
|
}
|
|
141
|
-
|
|
142
|
-
this[type].raw(String(data).trim());
|
|
143
|
-
};
|
|
144
|
-
}
|
|
168
|
+
|
|
145
169
|
restoreStd() {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
_restoreStream(stream) {
|
|
150
|
-
if (!stream) {
|
|
151
|
-
return;
|
|
170
|
+
this._restoreStream(this.options.stdout);
|
|
171
|
+
this._restoreStream(this.options.stderr);
|
|
152
172
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
173
|
+
|
|
174
|
+
_restoreStream(stream) {
|
|
175
|
+
if (!stream) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (stream.__write) {
|
|
180
|
+
stream.write = stream.__write;
|
|
181
|
+
delete stream.__write;
|
|
182
|
+
}
|
|
156
183
|
}
|
|
157
|
-
|
|
184
|
+
|
|
158
185
|
pauseLogs() {
|
|
159
|
-
|
|
160
|
-
|
|
186
|
+
paused = true;
|
|
187
|
+
}
|
|
188
|
+
|
|
161
189
|
resumeLogs() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
190
|
+
paused = false;
|
|
191
|
+
const _queue = queue.splice(0);
|
|
192
|
+
|
|
193
|
+
for (const item of _queue) {
|
|
194
|
+
item[0]._logFn(item[1], item[2]);
|
|
195
|
+
}
|
|
166
196
|
}
|
|
167
|
-
|
|
197
|
+
|
|
168
198
|
mockTypes(mockFn) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
199
|
+
const _mockFn = mockFn || this.options.mockFn;
|
|
200
|
+
|
|
201
|
+
this._mockFn = _mockFn;
|
|
202
|
+
if (!isFn(_mockFn)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
for (const type in this.options.types) {
|
|
207
|
+
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
|
208
|
+
this[type].raw = this[type];
|
|
209
|
+
}
|
|
177
210
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
211
|
+
|
|
212
|
+
_wrapLogFn(defaults, isRaw) {
|
|
213
|
+
return (...args) => {
|
|
214
|
+
if (paused) {
|
|
215
|
+
queue.push([
|
|
216
|
+
this,
|
|
217
|
+
defaults,
|
|
218
|
+
args,
|
|
219
|
+
isRaw,
|
|
220
|
+
]);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return this._logFn(defaults, args, isRaw);
|
|
225
|
+
};
|
|
191
226
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
227
|
+
|
|
228
|
+
_logFn(defaults, args, isRaw) {
|
|
229
|
+
if (this.level < (defaults.level || 0)) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const logObj = {
|
|
234
|
+
date: new Date(),
|
|
235
|
+
args: [],
|
|
236
|
+
...defaults,
|
|
237
|
+
level: _normalizeLogLevel(defaults.level, this.options.types),
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
|
241
|
+
Object.assign(logObj, args[0]);
|
|
242
|
+
} else {
|
|
243
|
+
logObj.args = args.slice();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (logObj.message) {
|
|
247
|
+
logObj.args.unshift(logObj.message);
|
|
248
|
+
delete logObj.message;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (logObj.additional) {
|
|
252
|
+
if (!Array.isArray(logObj.additional)) {
|
|
253
|
+
logObj.additional = logObj.additional.split('\n');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
logObj.args.push('\n' + logObj.additional.join('\n'));
|
|
257
|
+
delete logObj.additional;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
logObj.type = isString(logObj.type) ? logObj.type.toLowerCase() : 'log';
|
|
261
|
+
if (!isString(logObj.tag))
|
|
262
|
+
logObj.tag = '';
|
|
263
|
+
|
|
264
|
+
const resolveLog = (newLog = false) => {
|
|
265
|
+
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
266
|
+
|
|
267
|
+
if (this._lastLog.object && repeated > 0) {
|
|
268
|
+
const args2 = this._lastLog.object.args.slice();
|
|
269
|
+
|
|
270
|
+
if (repeated > 1) {
|
|
271
|
+
args2.push(`(repeated ${repeated} times)`);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
this._log({ ...this._lastLog.object,
|
|
275
|
+
args: args2});
|
|
276
|
+
this._lastLog.count = 1;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (newLog) {
|
|
280
|
+
this._lastLog.object = logObj;
|
|
281
|
+
this._log(logObj);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
clearTimeout(this._lastLog.timeout);
|
|
286
|
+
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
287
|
+
|
|
288
|
+
this._lastLog.time = logObj.date;
|
|
289
|
+
if (diffTime < this.options.throttle) {
|
|
290
|
+
try {
|
|
291
|
+
const serializedLog = JSON.stringify([
|
|
292
|
+
logObj.type,
|
|
293
|
+
logObj.tag,
|
|
294
|
+
logObj.args,
|
|
295
|
+
]);
|
|
296
|
+
|
|
297
|
+
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
298
|
+
|
|
299
|
+
this._lastLog.serialized = serializedLog;
|
|
300
|
+
if (isSameLog) {
|
|
301
|
+
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
302
|
+
if (this._lastLog.count > this.options.throttleMin) {
|
|
303
|
+
this._lastLog.timeout = setTimeout(resolveLog, this.options.throttle);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
} catch {}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
resolveLog(true);
|
|
202
311
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
312
|
+
|
|
313
|
+
_log(logObj) {
|
|
314
|
+
for (const reporter of this.options.reporters) {
|
|
315
|
+
reporter.log(logObj, {
|
|
316
|
+
options: this.options,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
206
319
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
logObj.args.push("\n" + logObj.additional.join("\n"));
|
|
212
|
-
delete logObj.additional;
|
|
320
|
+
}function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
321
|
+
if (input === void 0) {
|
|
322
|
+
return defaultLevel;
|
|
213
323
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
218
|
-
if (this._lastLog.object && repeated > 0) {
|
|
219
|
-
const args2 = [...this._lastLog.object.args];
|
|
220
|
-
if (repeated > 1) {
|
|
221
|
-
args2.push(`(repeated ${repeated} times)`);
|
|
222
|
-
}
|
|
223
|
-
this._log({ ...this._lastLog.object, args: args2 });
|
|
224
|
-
this._lastLog.count = 1;
|
|
225
|
-
}
|
|
226
|
-
if (newLog) {
|
|
227
|
-
this._lastLog.object = logObj;
|
|
228
|
-
this._log(logObj);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
clearTimeout(this._lastLog.timeout);
|
|
232
|
-
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
233
|
-
this._lastLog.time = logObj.date;
|
|
234
|
-
if (diffTime < this.options.throttle) {
|
|
235
|
-
try {
|
|
236
|
-
const serializedLog = JSON.stringify([
|
|
237
|
-
logObj.type,
|
|
238
|
-
logObj.tag,
|
|
239
|
-
logObj.args
|
|
240
|
-
]);
|
|
241
|
-
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
242
|
-
this._lastLog.serialized = serializedLog;
|
|
243
|
-
if (isSameLog) {
|
|
244
|
-
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
245
|
-
if (this._lastLog.count > this.options.throttleMin) {
|
|
246
|
-
this._lastLog.timeout = setTimeout(
|
|
247
|
-
resolveLog,
|
|
248
|
-
this.options.throttle
|
|
249
|
-
);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
} catch {
|
|
254
|
-
}
|
|
324
|
+
|
|
325
|
+
if (isNumber(input)) {
|
|
326
|
+
return input;
|
|
255
327
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
for (const reporter of this.options.reporters) {
|
|
260
|
-
reporter.log(logObj, {
|
|
261
|
-
options: this.options
|
|
262
|
-
});
|
|
328
|
+
|
|
329
|
+
if (types[input] && types[input].level !== void 0) {
|
|
330
|
+
return types[input].level;
|
|
263
331
|
}
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
267
|
-
if (input === void 0) {
|
|
332
|
+
|
|
268
333
|
return defaultLevel;
|
|
269
|
-
}
|
|
270
|
-
if (typeof input === "number") {
|
|
271
|
-
return input;
|
|
272
|
-
}
|
|
273
|
-
if (types[input] && types[input].level !== void 0) {
|
|
274
|
-
return types[input].level;
|
|
275
|
-
}
|
|
276
|
-
return defaultLevel;
|
|
277
334
|
}
|
|
335
|
+
|
|
278
336
|
Relinka.prototype.add = Relinka.prototype.addReporter;
|
|
279
337
|
Relinka.prototype.remove = Relinka.prototype.removeReporter;
|
|
280
338
|
Relinka.prototype.clear = Relinka.prototype.removeReporter;
|
|
@@ -283,5 +341,5 @@ Relinka.prototype.mock = Relinka.prototype.mockTypes;
|
|
|
283
341
|
Relinka.prototype.pause = Relinka.prototype.pauseLogs;
|
|
284
342
|
Relinka.prototype.resume = Relinka.prototype.resumeLogs;
|
|
285
343
|
export function createRelinka(options = {}) {
|
|
286
|
-
|
|
344
|
+
return new Relinka(options);
|
|
287
345
|
}
|