bajo 2.21.1 → 2.22.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/.jsdoc.conf.json +1 -1
- package/class/app.js +139 -115
- package/class/bajo.js +96 -89
- package/class/base.js +25 -9
- package/class/cache.js +32 -19
- package/class/err.js +11 -9
- package/class/log.js +102 -52
- package/class/plugin.js +45 -35
- package/class/print.js +45 -44
- package/class/tools.js +7 -1
- package/docs/App.html +1 -23
- package/docs/Bajo.html +1 -6
- package/docs/Base.html +1 -1
- package/docs/Cache.html +1 -1
- package/docs/Err.html +2 -2
- package/docs/Log.html +4 -4
- package/docs/Plugin.html +1 -1
- package/docs/Print.html +1 -1
- package/docs/Tools.html +1 -1
- package/docs/class_app.js.html +141 -117
- package/docs/class_bajo.js.html +98 -91
- package/docs/class_base.js.html +27 -11
- package/docs/class_cache.js.html +34 -21
- package/docs/class_err.js.html +13 -11
- package/docs/class_log.js.html +104 -54
- package/docs/class_plugin.js.html +47 -37
- package/docs/class_print.js.html +47 -46
- package/docs/class_tools.js.html +9 -3
- package/docs/data/search.json +1 -1
- package/docs/global.html +1 -1
- package/docs/index.html +1 -1
- package/docs/index.js.html +8 -4
- package/docs/{class__helper.js.html → lib_helper.js.html} +208 -96
- package/docs/lib_hook.js.html +231 -0
- package/docs/module-Helper.html +8 -1
- package/docs/module-Hook.html +3 -0
- package/docs/module-Lib.html +1 -8
- package/index.js +1 -1
- package/{class/_helper.js → lib/helper.js} +206 -94
- package/lib/hook.js +228 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +6 -0
- package/docs/class_helper_bajo.js.html +0 -398
- package/docs/class_helper_base.js.html +0 -246
- package/docs/class_misc_err.js.html +0 -129
- package/docs/class_misc_log.js.html +0 -210
- package/docs/class_misc_print.js.html +0 -267
- package/docs/lib_current-loc.js.html +0 -36
- package/docs/lib_find-deep.js.html +0 -27
- package/docs/lib_formats.js.html +0 -68
- package/docs/lib_freeze.js.html +0 -54
- package/docs/lib_import-module.js.html +0 -61
- package/docs/lib_index.js.html +0 -9
- package/docs/lib_log-levels.js.html +0 -38
- package/docs/lib_parse-args-argv.js.html +0 -83
- package/docs/lib_parse-env.js.html +0 -53
- package/docs/lib_resolve-path.js.html +0 -27
- package/docs/lib_shim.js.html +0 -40
- package/docs/module-Helper_Bajo.html +0 -3
- package/docs/module-Helper_Base.html +0 -3
- package/lib/find-deep.js +0 -24
- package/lib/formats.js +0 -65
- package/lib/freeze.js +0 -51
- package/lib/import-module.js +0 -58
- package/lib/index.js +0 -6
- package/lib/log-levels.js +0 -35
package/class/log.js
CHANGED
|
@@ -1,12 +1,49 @@
|
|
|
1
1
|
import os from 'os'
|
|
2
|
-
import logLevels from '../lib/log-levels.js'
|
|
3
2
|
import chalk from 'chalk'
|
|
4
3
|
import { stripVTControlCharacters } from 'node:util'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
6
|
+
* @typedef {Object} TLevels
|
|
7
|
+
* @memberof Log
|
|
8
|
+
* @type {Object}
|
|
9
|
+
* @property {Object} trace
|
|
10
|
+
* @property {number} [trace.number=10]
|
|
11
|
+
* @property {string} [trace.color=gray]
|
|
12
|
+
* @property {Object} debug
|
|
13
|
+
* @property {number} [debug.number=20]
|
|
14
|
+
* @property {string} [debug.color=greenBright]
|
|
15
|
+
* @property {Object} info
|
|
16
|
+
* @property {number} [info.number=30]
|
|
17
|
+
* @property {string} [info.color=blueBright]
|
|
18
|
+
* @property {Object} warn
|
|
19
|
+
* @property {number} [warn.number=40]
|
|
20
|
+
* @property {string} [warn.color=yellowBright]
|
|
21
|
+
* @property {Object} error
|
|
22
|
+
* @property {number} [error.number=50]
|
|
23
|
+
* @property {string} [error.color=redBright]
|
|
24
|
+
* @property {Object} fatal
|
|
25
|
+
* @property {number} [fatal.number=60]
|
|
26
|
+
* @property {string} [fatal.color=magentaBright]
|
|
27
|
+
* @property {Object} silent
|
|
28
|
+
* @property {number} [silent.number=99]
|
|
29
|
+
* @property {string} [silent.color=white]
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export const logLevels = {
|
|
33
|
+
trace: { number: 10, color: 'gray' },
|
|
34
|
+
debug: { number: 20, color: 'greenBright' },
|
|
35
|
+
info: { number: 30, color: 'blueBright' },
|
|
36
|
+
warn: { number: 40, color: 'yellowBright' },
|
|
37
|
+
error: { number: 50, color: 'redBright' },
|
|
38
|
+
fatal: { number: 60, color: 'magentaBright' },
|
|
39
|
+
silent: { number: 99, color: 'white' }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Log output in stringified JSON format. Returned when app run in `prod` environment.
|
|
8
44
|
*
|
|
9
|
-
* @typedef
|
|
45
|
+
* @typedef TJsonOutput
|
|
46
|
+
* @memberof Log
|
|
10
47
|
* @property {string} prefix Message prefix.
|
|
11
48
|
* @property {string} message The message itself.
|
|
12
49
|
* @property {string} level Log level.
|
|
@@ -20,32 +57,34 @@ import { stripVTControlCharacters } from 'node:util'
|
|
|
20
57
|
/**
|
|
21
58
|
* A thin & fast logger system.
|
|
22
59
|
*
|
|
23
|
-
* An instance is created by the {@link App|app} and available to use anywhere
|
|
24
|
-
*
|
|
25
|
-
* ```javascript
|
|
26
|
-
* ... anywhere inside your code
|
|
27
|
-
* this.app.log.debug(...)
|
|
28
|
-
* ```
|
|
60
|
+
* An instance is created by the {@link App|app} and available to use from anywhere inside your code.
|
|
29
61
|
*
|
|
30
62
|
* Shortcuts to log's methods are also available on every Bajo {@link Plugin|plugin}. Call on
|
|
31
|
-
* these shortcuts will be prefixed with it's plugin name automatically
|
|
63
|
+
* these shortcuts will be prefixed with it's plugin name automatically.
|
|
32
64
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
65
|
+
* Example:
|
|
66
|
+
* ```js
|
|
67
|
+
* // ... anywhere inside your code
|
|
68
|
+
* this.app.log.debug(...)
|
|
69
|
+
* // or inside a plugin
|
|
70
|
+
* if (!isValid) this.log.error('Invalid value!') // will be prefixed with plugin namespace automatically
|
|
36
71
|
* ```
|
|
37
72
|
*
|
|
38
73
|
* @class
|
|
39
74
|
*/
|
|
40
75
|
class Log {
|
|
41
76
|
/**
|
|
77
|
+
* Constructor.
|
|
42
78
|
* @param {App} app - App instance
|
|
43
79
|
*/
|
|
44
80
|
constructor (app) {
|
|
45
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Last delta time in millisecond since app started. Used for log's time taken feature.
|
|
83
|
+
* @type {number}
|
|
84
|
+
*/
|
|
85
|
+
this._lastDelta = 0
|
|
46
86
|
/**
|
|
47
87
|
* The app instance.
|
|
48
|
-
*
|
|
49
88
|
* @type {App}
|
|
50
89
|
*/
|
|
51
90
|
this.app = app
|
|
@@ -57,18 +96,18 @@ class Log {
|
|
|
57
96
|
|
|
58
97
|
/**
|
|
59
98
|
* Display & format message according to one of these rules:
|
|
60
|
-
* 1.
|
|
61
|
-
* 2.
|
|
62
|
-
* 3.
|
|
99
|
+
* 1. `level` `prefix` `text` `var 1` `var 2` `...var n` - Translate `text` and interpolate with `vars` for level `level`
|
|
100
|
+
* 2. `level` `prefix` `data` `text` `var 1` `var 2` `...var n` - As above, and append stringified `data`
|
|
101
|
+
* 3. `level` `prefix` `error` - Format as {@link Err} object. If current log level is _trace_, dump it on screen
|
|
63
102
|
*
|
|
64
|
-
* In
|
|
103
|
+
* In `prod` environment, log will be delivered as JSON stringified object. See {@link Log.TJsonOutput} for more info
|
|
65
104
|
*
|
|
66
105
|
* @method
|
|
67
|
-
* @param {string} level Log level to use
|
|
68
|
-
* @param {string} prefix Prefix to the message
|
|
69
|
-
* @param {...any} params See format above
|
|
106
|
+
* @param {string} level - Log level to use
|
|
107
|
+
* @param {string} prefix - Prefix to the message
|
|
108
|
+
* @param {...any} params - See format above
|
|
70
109
|
* @see Err
|
|
71
|
-
* @see
|
|
110
|
+
* @see Log.TJsonOutput
|
|
72
111
|
*/
|
|
73
112
|
formatMsg = (level, prefix, ...params) => {
|
|
74
113
|
const { dayjs } = this.app.lib
|
|
@@ -95,8 +134,8 @@ class Log {
|
|
|
95
134
|
let diff = null
|
|
96
135
|
if (timeTaken) {
|
|
97
136
|
const delta = dt.diff(this.app.runAt, 'ms')
|
|
98
|
-
diff = delta - this.
|
|
99
|
-
this.
|
|
137
|
+
diff = delta - this._lastDelta
|
|
138
|
+
this._lastDelta = delta
|
|
100
139
|
}
|
|
101
140
|
if (this.app.bajo.config.env === 'prod') {
|
|
102
141
|
const json = { prefix, msg, level: logLevels[level].number, time: dt.valueOf(), pid: process.pid, hostname: os.hostname() }
|
|
@@ -121,17 +160,24 @@ class Log {
|
|
|
121
160
|
if (this.app.bajo.config.log.save) this.save(text, prefix)
|
|
122
161
|
}
|
|
123
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Get error message from an Error object. If the message is empty, return the code or statusCode instead.
|
|
165
|
+
*
|
|
166
|
+
* @method
|
|
167
|
+
* @param {Error} error - Error object
|
|
168
|
+
* @returns {string} Error message
|
|
169
|
+
*/
|
|
124
170
|
getErrorMessage = error => {
|
|
125
171
|
const { isEmpty } = this.app.lib._
|
|
126
172
|
return isEmpty(error.message) ? (error.code ?? error.statusCode) : error.message
|
|
127
173
|
}
|
|
128
174
|
|
|
129
175
|
/**
|
|
130
|
-
* Calculate pattern used for log rotation.
|
|
176
|
+
* Calculate pattern used for log rotation. Used by {@link Log#save|save} method to determine the log file name.
|
|
131
177
|
*
|
|
132
178
|
* @method
|
|
133
|
-
* @param {boolean} isPrev If true
|
|
134
|
-
* @returns {string} Calculated pattern
|
|
179
|
+
* @param {boolean} isPrev - If `true`, calculate previous rotation pattern.
|
|
180
|
+
* @returns {string} Calculated pattern
|
|
135
181
|
*/
|
|
136
182
|
getRotationPattern = (isPrev) => {
|
|
137
183
|
const { dayjs } = this.app.lib
|
|
@@ -160,11 +206,11 @@ class Log {
|
|
|
160
206
|
}
|
|
161
207
|
|
|
162
208
|
/**
|
|
163
|
-
* Save log to file in {dataDir}/log
|
|
209
|
+
* Save log to file in `{dataDir}/log`.
|
|
164
210
|
*
|
|
165
211
|
* @method
|
|
166
|
-
* @param {string} text Log message to save
|
|
167
|
-
* @param {string} prefix Use prefix as basename. Defaults to
|
|
212
|
+
* @param {string} text - Log message to save
|
|
213
|
+
* @param {string} [prefix='bajo'] - Use prefix as basename. Defaults to `bajo`
|
|
168
214
|
*/
|
|
169
215
|
save = (text, prefix = 'bajo') => {
|
|
170
216
|
const { fs } = this.app.lib
|
|
@@ -180,77 +226,77 @@ class Log {
|
|
|
180
226
|
}
|
|
181
227
|
|
|
182
228
|
/**
|
|
183
|
-
* Display & format message in
|
|
229
|
+
* Display & format message in `trace` level. See {@link Log#formatMsg|formatMsg} for details.
|
|
184
230
|
*
|
|
185
231
|
* @method
|
|
186
|
-
* @param {string} prefix Message prefix
|
|
187
|
-
* @param {...any} params Parameters
|
|
232
|
+
* @param {string} prefix - Message prefix
|
|
233
|
+
* @param {...any} params - Parameters
|
|
188
234
|
*/
|
|
189
235
|
trace = (prefix, ...params) => {
|
|
190
236
|
this.formatMsg('trace', prefix, ...params)
|
|
191
237
|
}
|
|
192
238
|
|
|
193
239
|
/**
|
|
194
|
-
* Display & format message in
|
|
240
|
+
* Display & format message in `debug` level. See {@link Log#formatMsg|formatMsg} for details.
|
|
195
241
|
*
|
|
196
242
|
* @method
|
|
197
|
-
* @param {string} prefix Message prefix
|
|
198
|
-
* @param {...any} params Parameters
|
|
243
|
+
* @param {string} prefix - Message prefix
|
|
244
|
+
* @param {...any} params - Parameters
|
|
199
245
|
*/
|
|
200
246
|
debug = (prefix, ...params) => {
|
|
201
247
|
this.formatMsg('debug', prefix, ...params)
|
|
202
248
|
}
|
|
203
249
|
|
|
204
250
|
/**
|
|
205
|
-
* Display & format message in
|
|
251
|
+
* Display & format message in `info` level. See {@link Log#formatMsg|formatMsg} for details.
|
|
206
252
|
*
|
|
207
253
|
* @method
|
|
208
|
-
* @param {string} prefix Message prefix
|
|
209
|
-
* @param {...any} params Parameters
|
|
254
|
+
* @param {string} prefix - Message prefix
|
|
255
|
+
* @param {...any} params - Parameters
|
|
210
256
|
*/
|
|
211
257
|
info = (prefix, ...params) => {
|
|
212
258
|
this.formatMsg('info', prefix, ...params)
|
|
213
259
|
}
|
|
214
260
|
|
|
215
261
|
/**
|
|
216
|
-
* Display & format message in
|
|
262
|
+
* Display & format message in `warn` level. See {@link Log#formatMsg|formatMsg} for details.
|
|
217
263
|
*
|
|
218
264
|
* @method
|
|
219
|
-
* @param {string} prefix Message prefix
|
|
220
|
-
* @param {...any} params Parameters
|
|
265
|
+
* @param {string} prefix - Message prefix
|
|
266
|
+
* @param {...any} params - Parameters
|
|
221
267
|
*/
|
|
222
268
|
warn = (prefix, ...params) => {
|
|
223
269
|
this.formatMsg('warn', prefix, ...params)
|
|
224
270
|
}
|
|
225
271
|
|
|
226
272
|
/**
|
|
227
|
-
* Display & format message in
|
|
273
|
+
* Display & format message in `error` level. See {@link Log#formatMsg|formatMsg} for details.
|
|
228
274
|
*
|
|
229
275
|
* @method
|
|
230
|
-
* @param {string} prefix Message prefix
|
|
231
|
-
* @param {...any} params Parameters
|
|
276
|
+
* @param {string} prefix - Message prefix
|
|
277
|
+
* @param {...any} params - Parameters
|
|
232
278
|
*/
|
|
233
279
|
error = (prefix, ...params) => {
|
|
234
280
|
this.formatMsg('error', prefix, ...params)
|
|
235
281
|
}
|
|
236
282
|
|
|
237
283
|
/**
|
|
238
|
-
* Display & format message in
|
|
284
|
+
* Display & format message in `fatal` level. See {@link Log#formatMsg|formatMsg} for details.
|
|
239
285
|
*
|
|
240
286
|
* @method
|
|
241
|
-
* @param {string} prefix Message prefix
|
|
242
|
-
* @param {...any} params Parameters
|
|
287
|
+
* @param {string} prefix - Message prefix
|
|
288
|
+
* @param {...any} params - Parameters
|
|
243
289
|
*/
|
|
244
290
|
fatal = (prefix, ...params) => {
|
|
245
291
|
this.formatMsg('fatal', prefix, ...params)
|
|
246
292
|
}
|
|
247
293
|
|
|
248
294
|
/**
|
|
249
|
-
* Display & format message in
|
|
295
|
+
* Display & format message in `silent` level. See {@link Log#formatMsg|formatMsg} for details.
|
|
250
296
|
*
|
|
251
297
|
* @method
|
|
252
|
-
* @param {string} prefix Message prefix
|
|
253
|
-
* @param {...any} params Parameters
|
|
298
|
+
* @param {string} prefix - Message prefix
|
|
299
|
+
* @param {...any} params - Parameters
|
|
254
300
|
*/
|
|
255
301
|
silent = (prefix, ...params) => {
|
|
256
302
|
this.formatMsg('silent', prefix, ...params)
|
|
@@ -258,6 +304,10 @@ class Log {
|
|
|
258
304
|
|
|
259
305
|
/**
|
|
260
306
|
* Dispose internal references.
|
|
307
|
+
*
|
|
308
|
+
* @async
|
|
309
|
+
* @method
|
|
310
|
+
* @returns {Promise<void>}
|
|
261
311
|
*/
|
|
262
312
|
dispose = async () => {
|
|
263
313
|
this.app = null
|
package/class/plugin.js
CHANGED
|
@@ -15,23 +15,23 @@ const { get, isEmpty, cloneDeep, omit, isPlainObject, camelCase } = lodash
|
|
|
15
15
|
*/
|
|
16
16
|
class Plugin {
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Constructor.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} pkgName - Package name (the one in package.json)
|
|
21
|
+
* @param {Object} app - App instance reference. Usefull to call app method inside a plugin
|
|
20
22
|
*/
|
|
21
23
|
constructor (pkgName, app) {
|
|
22
24
|
/**
|
|
23
25
|
* Package name, the one from package.json.
|
|
24
26
|
*
|
|
25
|
-
* @
|
|
26
|
-
* @constant {string}
|
|
27
|
+
* @type {string}
|
|
27
28
|
*/
|
|
28
29
|
this.pkgName = pkgName
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* Namespace (ns) or plugin's name.
|
|
32
|
+
* Namespace (ns) or plugin's name. It is the camel cased version of plugin's package name.
|
|
32
33
|
*
|
|
33
|
-
* @
|
|
34
|
-
* @constant {string}
|
|
34
|
+
* @type {string}
|
|
35
35
|
*/
|
|
36
36
|
this.ns = camelCase(pkgName)
|
|
37
37
|
|
|
@@ -40,20 +40,18 @@ class Plugin {
|
|
|
40
40
|
* Bajo will provide this automatically (by using the kebab-cased version of plugin name).
|
|
41
41
|
*
|
|
42
42
|
* @readonly
|
|
43
|
-
* @memberof Plugin
|
|
44
43
|
* @type {string}
|
|
45
44
|
*/
|
|
46
45
|
this.alias = null
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
|
-
* Reference to the app instance
|
|
50
|
-
*
|
|
51
|
-
* @type {Object}
|
|
48
|
+
* Reference to the app instance
|
|
49
|
+
* @type {App}
|
|
52
50
|
*/
|
|
53
51
|
this.app = app
|
|
54
52
|
|
|
55
53
|
/**
|
|
56
|
-
*
|
|
54
|
+
* Configuration object.
|
|
57
55
|
*
|
|
58
56
|
* @type {Object}
|
|
59
57
|
* @see {@tutorial config}
|
|
@@ -80,8 +78,9 @@ class Plugin {
|
|
|
80
78
|
* Get package info.
|
|
81
79
|
*
|
|
82
80
|
* @method
|
|
83
|
-
* @param {string} [dir] Package directory. Defaults to the current plugin's package dir
|
|
84
|
-
* @param {Array} [keys=['name', 'version', 'description', 'author', 'license', 'homepage', 'bajo']] Field keys to be use. Set empty to use all keys
|
|
81
|
+
* @param {string} [dir] - Package directory. Defaults to the current plugin's package dir
|
|
82
|
+
* @param {Array} [keys=['name', 'version', 'description', 'author', 'license', 'homepage', 'bajo']] - Field keys to be use. Set empty to use all keys
|
|
83
|
+
* @returns {Object} Package info object
|
|
85
84
|
*/
|
|
86
85
|
getPkgInfo = (dir, keys = ['name', 'version', 'description', 'author', 'license', 'homepage', 'bajo']) => {
|
|
87
86
|
const { pick, isEmpty } = this.app.lib._
|
|
@@ -95,12 +94,12 @@ class Plugin {
|
|
|
95
94
|
* Get plugin's config value.
|
|
96
95
|
*
|
|
97
96
|
* @method
|
|
98
|
-
* @param {string} [path] dot separated config path (think of lodash's 'get'). If not provided, the full config will be given
|
|
99
|
-
* @param {Object} [options={}] Options
|
|
100
|
-
* @param {any} [options.defValue={}] Default value to use if returned object is undefined
|
|
101
|
-
* @param {string[]} [options.omit=[]] Omit these keys from returned object
|
|
102
|
-
* @param {boolean} [options.noClone=false] Set true to NOT clone returned object
|
|
103
|
-
* @returns {Object} Returned object. If no path provided, the whole config object is returned
|
|
97
|
+
* @param {string} [path] - dot separated config path (think of lodash's 'get'). If not provided, the full config will be given
|
|
98
|
+
* @param {Object} [options={}] - Options object
|
|
99
|
+
* @param {any} [options.defValue={}] - Default value to use if returned object is undefined
|
|
100
|
+
* @param {string[]} [options.omit=[]] - Omit these keys from returned object
|
|
101
|
+
* @param {boolean} [options.noClone=false] - Set true to NOT clone returned object
|
|
102
|
+
* @returns {Object} Returned object. If no path provided, the whole config object is returned
|
|
104
103
|
*/
|
|
105
104
|
getConfig = (path, options = {}) => {
|
|
106
105
|
let obj = isEmpty(path) ? this.config : get(this.config, path, options.defValue ?? {})
|
|
@@ -114,9 +113,9 @@ class Plugin {
|
|
|
114
113
|
* Create an instance of {@link Err} object.
|
|
115
114
|
*
|
|
116
115
|
* @method
|
|
117
|
-
* @param {string} msg Error message
|
|
118
|
-
* @param {...any} [args] Argument variables you might want to add to the error object
|
|
119
|
-
* @returns {
|
|
116
|
+
* @param {string} msg - Error message
|
|
117
|
+
* @param {...any} [args] - Argument variables you might want to add to the error object
|
|
118
|
+
* @returns {Err} Err instance
|
|
120
119
|
*/
|
|
121
120
|
error = (msg, ...args) => {
|
|
122
121
|
if (!this.print) return new Error(msg, ...args)
|
|
@@ -126,11 +125,12 @@ class Plugin {
|
|
|
126
125
|
|
|
127
126
|
/**
|
|
128
127
|
* Create an instance of Err object, display it on screen and then force
|
|
129
|
-
* terminate the app
|
|
128
|
+
* terminate the app.
|
|
130
129
|
*
|
|
131
130
|
* @method
|
|
132
|
-
* @param {string} msg Error message
|
|
133
|
-
* @param {...any} [args] Argument variables you might want to add to the error object
|
|
131
|
+
* @param {string} msg - Error message
|
|
132
|
+
* @param {...any} [args] - Argument variables you might want to add to the error object
|
|
133
|
+
* @returns {void}
|
|
134
134
|
*/
|
|
135
135
|
fatal = (msg, ...args) => {
|
|
136
136
|
if (!this.print) return new Error(msg, ...args)
|
|
@@ -139,12 +139,13 @@ class Plugin {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
|
-
* Translate text and interpolate with given
|
|
142
|
+
* Translate text and interpolate with given `args`.
|
|
143
143
|
*
|
|
144
144
|
* Shortcut to {@link App#t} with ns parameter set to this plugin namespace.
|
|
145
145
|
*
|
|
146
|
-
* @
|
|
147
|
-
* @param
|
|
146
|
+
* @method
|
|
147
|
+
* @param {string} text - Text to translate
|
|
148
|
+
* @param {...any} params - Variables to interpolate to `text`
|
|
148
149
|
* @returns {string}
|
|
149
150
|
*/
|
|
150
151
|
t = (text, ...params) => {
|
|
@@ -156,8 +157,9 @@ class Plugin {
|
|
|
156
157
|
*
|
|
157
158
|
* Shortcut to {@link App#te} with ns parameter set to this plugin namespace.
|
|
158
159
|
*
|
|
159
|
-
* @
|
|
160
|
-
* @param
|
|
160
|
+
* @method
|
|
161
|
+
* @param {string} text - Text to translate
|
|
162
|
+
* @param {...any} params - Variables to interpolate to `text`
|
|
161
163
|
* @returns {string}
|
|
162
164
|
*/
|
|
163
165
|
te = (text, ...params) => {
|
|
@@ -165,9 +167,11 @@ class Plugin {
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
/**
|
|
168
|
-
* Force bind methods to self (
|
|
170
|
+
* Force bind methods to self (`this`).
|
|
169
171
|
*
|
|
170
|
-
* @
|
|
172
|
+
* @method
|
|
173
|
+
* @param {string[]} names - Method's names
|
|
174
|
+
* @returns {void}
|
|
171
175
|
*/
|
|
172
176
|
selfBind (names) {
|
|
173
177
|
if (!Array.isArray(names)) names = [names]
|
|
@@ -177,9 +181,11 @@ class Plugin {
|
|
|
177
181
|
}
|
|
178
182
|
|
|
179
183
|
/**
|
|
180
|
-
* Alias to
|
|
184
|
+
* Alias to `this.app.dump()`.
|
|
181
185
|
*
|
|
182
|
-
* @
|
|
186
|
+
* @method
|
|
187
|
+
* @param {...any} args - Arguments
|
|
188
|
+
* @returns {void}
|
|
183
189
|
*/
|
|
184
190
|
dump = (...args) => {
|
|
185
191
|
this.app.dump(...args)
|
|
@@ -187,6 +193,10 @@ class Plugin {
|
|
|
187
193
|
|
|
188
194
|
/**
|
|
189
195
|
* Dispose internal references.
|
|
196
|
+
*
|
|
197
|
+
* @async
|
|
198
|
+
* @method
|
|
199
|
+
* @returns {Promise<void>}
|
|
190
200
|
*/
|
|
191
201
|
dispose = async () => {
|
|
192
202
|
this.app = null
|