bajo 0.2.10 → 0.2.12

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.
@@ -20,6 +20,7 @@ function format (...args) {
20
20
  const { ns, msg, params, opts } = prep(args)
21
21
  if (!msg) return ''
22
22
  const i18n = get(this, 'bajoI18N.instance')
23
+ const dayjs = get(this, 'bajo.helper')
23
24
  if (i18n) {
24
25
  if (isPlainObject(params[0])) {
25
26
  const ctx = merge({}, params[0] ?? {}, { ns })
@@ -34,7 +35,9 @@ function format (...args) {
34
35
  }
35
36
  return i18n.t(msg, { ns, pkg: opts.pkg, postProcess: 'sprintf', sprintf: params })
36
37
  }
37
- return sprintf(msg, ...params)
38
+ let text = sprintf(msg, ...params)
39
+ if (opts.showDatetime && dayjs) text = `[${dayjs().toISOString()}] ${text}`
40
+ return text
38
41
  }
39
42
 
40
43
  const print = {
package/boot/lib/bora.js CHANGED
@@ -29,7 +29,7 @@ class Bora {
29
29
  }
30
30
 
31
31
  setText (text, ...args) {
32
- const { dayjs, secToHms } = this.scope.bajo.helper
32
+ const { dayjs } = this.scope.bajo.helper
33
33
  if (isString(text)) {
34
34
  const i18n = get(this, 'scope.bajoI18N.instance')
35
35
  if (i18n) {
@@ -38,16 +38,22 @@ class Bora {
38
38
  } else text = sprintf(text, ...args)
39
39
  let opts = last(args)
40
40
  if (!isPlainObject(opts)) opts = {}
41
- const elapsed = dayjs().diff(this.startTime, 'second')
42
41
  const texts = []
43
42
  if (this.opts.showDatetime || opts.showDatetime) texts.push('[' + dayjs().toISOString() + ']')
44
- if (this.opts.showCounter || opts.showCounter) texts.push('[' + secToHms(elapsed) + ']')
43
+ if (this.opts.showCounter || opts.showCounter) texts.push('[' + this.getElapsed() + ']')
45
44
  texts.push(text)
46
45
  this.ora.text = texts.join(' ')
47
46
  }
48
47
  return this
49
48
  }
50
49
 
50
+ getElapsed (unit = 'hms') {
51
+ const { dayjs, secToHms } = this.scope.bajo.helper
52
+ const u = unit === 'hms' ? 'second' : unit
53
+ const elapsed = dayjs().diff(this.startTime, u)
54
+ return unit === 'hms' ? secToHms(elapsed) : elapsed
55
+ }
56
+
51
57
  start (text, ...args) {
52
58
  this.setText(text, ...args)
53
59
  this.ora.start()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {