@e-mc/module 0.8.1 → 0.8.2

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/README.md +2 -0
  2. package/index.js +56 -46
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ### @e-mc/module
2
2
 
3
+ https://e-mc.readthedocs.io
4
+
3
5
  ### LICENSE
4
6
 
5
7
  BSD 3-Clause
package/index.js CHANGED
@@ -41,7 +41,8 @@ const SETTINGS = {
41
41
  format: {
42
42
  title: {
43
43
  width: 6,
44
- justify: 'right'
44
+ justify: 'right',
45
+ as: {}
45
46
  },
46
47
  value: {
47
48
  width: 71,
@@ -49,7 +50,8 @@ const SETTINGS = {
49
50
  },
50
51
  hint: {
51
52
  width: 32,
52
- unit: 'auto'
53
+ unit: 'auto',
54
+ as: {}
53
55
  },
54
56
  meter: {
55
57
  width: Infinity,
@@ -621,7 +623,7 @@ class Module extends EventEmitter {
621
623
  this[_f] = new AbortController();
622
624
  this[_g] = null;
623
625
  }
624
- static get VERSION() { return "0.8.1" /* INTERNAL.VERSION */; }
626
+ static get VERSION() { return "0.8.2" /* INTERNAL.VERSION */; }
625
627
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
626
628
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
627
629
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -900,10 +902,11 @@ class Module extends EventEmitter {
900
902
  }
901
903
  }
902
904
  }
903
- title = titleIndent !== -1 ? ' '.repeat(titleIndent || (formatTitle.width + 3)) : (0, types_1.isString)(title) ? alignColumn(title.toUpperCase(), formatTitle.width, titleJustify, 1) : '';
904
- if (hint) {
905
+ title = titleIndent !== -1 ? ' '.repeat(titleIndent || (formatTitle.width + 3)) : (0, types_1.isString)(title) ? (title = title.toUpperCase(), alignColumn(formatTitle.as[title] || title, formatTitle.width, titleJustify, 1)) : '';
906
+ if ((0, types_1.isString)(hint)) {
905
907
  const formatHint = format.hint;
906
908
  let { hintColor, hintBgColor, hintBold } = options, hintWidth = formatHint.width;
909
+ hint = formatHint.as[hint] || hint;
907
910
  valueWidth -= Math.min(hint.length, hintWidth) + 2;
908
911
  if (hint.length > hintWidth && value.length + 1 < valueWidth) {
909
912
  const offset = Math.min(valueWidth - (value.length + 1), hint.length - hintWidth);
@@ -2232,44 +2235,53 @@ class Module extends EventEmitter {
2232
2235
  switch (attr) {
2233
2236
  case 'format': {
2234
2237
  const format = logger.format;
2235
- if ((0, types_1.isPlainObject)(format)) {
2236
- for (const section in format) {
2237
- const stored = SETTINGS.format[section];
2238
- const target = format[section];
2239
- if (stored && (0, types_1.isPlainObject)(target)) {
2240
- for (let name in target) {
2241
- const value = target[name];
2242
- switch (name) {
2243
- case 'bg_color':
2244
- name = 'bgColor';
2245
- break;
2246
- case 'bg_alt_color':
2247
- name = 'bgAltColor';
2248
- break;
2238
+ for (const section in format) {
2239
+ const stored = SETTINGS.format[section];
2240
+ const target = format[section];
2241
+ if (stored && (0, types_1.isPlainObject)(target)) {
2242
+ for (let name in target) {
2243
+ const value = target[name];
2244
+ switch (name) {
2245
+ case 'bg_color':
2246
+ name = 'bgColor';
2247
+ break;
2248
+ case 'bg_alt_color':
2249
+ name = 'bgAltColor';
2250
+ break;
2251
+ }
2252
+ switch (name) {
2253
+ case 'width': {
2254
+ const width = parseInt(value);
2255
+ if (width > 0) {
2256
+ stored[name] = width;
2257
+ }
2258
+ break;
2249
2259
  }
2250
- switch (name) {
2251
- case 'width': {
2252
- const width = parseInt(value);
2253
- if (width > 0) {
2254
- stored[name] = width;
2255
- }
2256
- break;
2260
+ case 'bold':
2261
+ if (typeof value === 'boolean') {
2262
+ stored[name] = value;
2257
2263
  }
2258
- case 'bold':
2259
- if (typeof value === 'boolean') {
2260
- stored[name] = value;
2261
- }
2262
- break;
2263
- case 'color':
2264
- case 'bgColor':
2265
- case 'bgAltColor':
2266
- case 'justify':
2267
- case 'unit':
2268
- if (typeof value === 'string') {
2269
- stored[name] = value;
2264
+ break;
2265
+ case 'color':
2266
+ case 'bgColor':
2267
+ case 'bgAltColor':
2268
+ case 'justify':
2269
+ case 'unit':
2270
+ if (typeof value === 'string') {
2271
+ stored[name] = value;
2272
+ }
2273
+ break;
2274
+ case 'as':
2275
+ if ((section === 'title' || section === 'hint') && (0, types_1.isPlainObject)(value)) {
2276
+ const data = {};
2277
+ for (const as in value) {
2278
+ if (typeof value[as] === 'string') {
2279
+ data[section === 'title' ? as.toUpperCase() : as] = value[as];
2280
+ }
2270
2281
  }
2271
- break;
2272
- }
2282
+ Object.assign(stored[name], data);
2283
+ }
2284
+ break;
2273
2285
  }
2274
2286
  }
2275
2287
  }
@@ -2278,12 +2290,10 @@ class Module extends EventEmitter {
2278
2290
  }
2279
2291
  case 'meter': {
2280
2292
  const meter = logger.meter;
2281
- if ((0, types_1.isPlainObject)(meter)) {
2282
- for (const name in meter) {
2283
- const increment = +meter[name];
2284
- if (increment > 0) {
2285
- SETTINGS.meter[name] = increment;
2286
- }
2293
+ for (const name in meter) {
2294
+ const increment = +meter[name];
2295
+ if (increment > 0) {
2296
+ SETTINGS.meter[name] = increment;
2287
2297
  }
2288
2298
  }
2289
2299
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Module base class for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.8.1",
23
+ "@e-mc/types": "0.8.2",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",