@e-mc/module 0.8.10 → 0.8.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.
Files changed (3) hide show
  1. package/README.md +5 -5
  2. package/index.js +49 -50
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -232,10 +232,10 @@ interface ModuleConstructor {
232
232
 
233
233
  ## References
234
234
 
235
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/core.d.ts
236
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/logger.d.ts
237
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/module.d.ts
238
- - https://www.unpkg.com/@e-mc/types@0.8.10/lib/node.d.ts
235
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/core.d.ts
236
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/logger.d.ts
237
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/module.d.ts
238
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/node.d.ts
239
239
 
240
240
  ## LICENSE
241
241
 
package/index.js CHANGED
@@ -220,7 +220,7 @@ function applyStyle(options, style) {
220
220
  }
221
221
  function checkColorOptions(type, settings, options) {
222
222
  var _h, _j, _k, _l;
223
- if (typeof settings !== 'object') {
223
+ if (!(0, types_1.isObject)(settings)) {
224
224
  return false;
225
225
  }
226
226
  let result = false;
@@ -642,14 +642,15 @@ function withinDir(value, base) {
642
642
  value = path.normalize(value);
643
643
  return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
644
644
  }
645
- function formatPercent(value, precision = 3) {
645
+ function formatPercent(value, precision) {
646
646
  if (value <= 0) {
647
647
  return '0%';
648
648
  }
649
- if (value === Math.floor(value)) {
649
+ if (value === (value | 0)) {
650
650
  return value + '00%';
651
651
  }
652
- return (value * 100).toPrecision(precision) + '%';
652
+ value *= 100;
653
+ return value.toPrecision(value < 1 ? 2 : precision) + '%';
653
654
  }
654
655
  const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
655
656
  const asFile = (value) => (0, types_1.isString)(value) ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
@@ -687,7 +688,7 @@ class Module extends EventEmitter {
687
688
  this[_f] = new AbortController();
688
689
  this[_g] = null;
689
690
  }
690
- static get VERSION() { return "0.8.10"; }
691
+ static get VERSION() { return "0.8.12"; }
691
692
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
692
693
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
693
694
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -1796,7 +1797,7 @@ class Module extends EventEmitter {
1796
1797
  const usage = user + system;
1797
1798
  result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
1798
1799
  }
1799
- return format ? formatPercent(result) : result;
1800
+ return format ? formatPercent(result, 3) : result;
1800
1801
  }
1801
1802
  }
1802
1803
  return format ? '' : 0;
@@ -1826,7 +1827,7 @@ class Module extends EventEmitter {
1826
1827
  return (0, types_1.formatSize)(result, { unit });
1827
1828
  }
1828
1829
  }
1829
- return format ? formatPercent(result / MEM_TOTAL) : result;
1830
+ return format ? formatPercent(result / MEM_TOTAL, 3) : result;
1830
1831
  }
1831
1832
  static formatCpuMem(start, all) {
1832
1833
  let cpu, cpu_bar, cpu_single_core, mem, mem_format;
@@ -1857,7 +1858,7 @@ class Module extends EventEmitter {
1857
1858
  }
1858
1859
  const unit = Math.max(bar, 10);
1859
1860
  const length = Math.floor(usage * unit);
1860
- const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
1861
+ const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
1861
1862
  result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
1862
1863
  }
1863
1864
  else if (usage) {
@@ -1867,7 +1868,7 @@ class Module extends EventEmitter {
1867
1868
  if (mem || all) {
1868
1869
  const usage = this.getMemUsage(mem_format || true);
1869
1870
  if (usage) {
1870
- result += (result ? ' ' : '') + usage + ' MEM';
1871
+ result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
1871
1872
  }
1872
1873
  }
1873
1874
  return result;
@@ -2276,7 +2277,7 @@ class Module extends EventEmitter {
2276
2277
  if ((0, types_1.isArray)(include)) {
2277
2278
  MEMORY_CACHE_DISK.include = include.map(value => this.toPosix(value, true));
2278
2279
  }
2279
- else if ((0, types_1.isArray)(exclude)) {
2280
+ if ((0, types_1.isArray)(exclude)) {
2280
2281
  MEMORY_CACHE_DISK.exclude = exclude.map(value => this.toPosix(value, true));
2281
2282
  }
2282
2283
  }
@@ -2457,52 +2458,50 @@ class Module extends EventEmitter {
2457
2458
  });
2458
2459
  }
2459
2460
  }
2460
- {
2461
- let dir = settings.temp_dir, write, modified;
2462
- if ((0, types_1.isPlainObject)(temp)) {
2463
- dir || (dir = temp.dir);
2464
- write = temp.write;
2465
- }
2466
- if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
2467
- if (withinDir(dir, PROCESS_CWD)) {
2468
- dir = dir.substring(ensureDir(PROCESS_CWD).length);
2469
- }
2470
- else {
2471
- this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
2472
- dir = undefined;
2473
- }
2474
- }
2475
- if (!(0, types_1.isString)(dir)) {
2476
- dir = VALUES["temp.dir"];
2461
+ let dir = settings.temp_dir, write, modified;
2462
+ if ((0, types_1.isPlainObject)(temp)) {
2463
+ dir || (dir = temp.dir);
2464
+ write = temp.write;
2465
+ }
2466
+ if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
2467
+ if (withinDir(dir, PROCESS_CWD)) {
2468
+ dir = dir.substring(ensureDir(PROCESS_CWD).length);
2477
2469
  }
2478
- if (typeof write === 'boolean') {
2479
- modified = VALUES["temp.write"] !== write;
2480
- VALUES["temp.write"] = write;
2470
+ else {
2471
+ this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
2472
+ dir = undefined;
2481
2473
  }
2482
- do {
2483
- const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
2484
- if ((0, types_1.isString)(output)) {
2485
- if (index > 0) {
2486
- dir = trimDir(dir) + '_' + index;
2487
- }
2488
- if (dir !== VALUES["temp.dir"]) {
2489
- VALUES["temp.dir"] = dir;
2490
- modified = true;
2491
- }
2492
- (0, types_1.setTempDir)(TEMP_DIR = output);
2493
- break;
2474
+ }
2475
+ if (!(0, types_1.isString)(dir)) {
2476
+ dir = VALUES["temp.dir"];
2477
+ }
2478
+ if (typeof write === 'boolean') {
2479
+ modified = VALUES["temp.write"] !== write;
2480
+ VALUES["temp.write"] = write;
2481
+ }
2482
+ do {
2483
+ const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
2484
+ if ((0, types_1.isString)(output)) {
2485
+ if (index > 0) {
2486
+ dir = trimDir(dir) + '_' + index;
2494
2487
  }
2495
- if (output instanceof Error) {
2496
- this.writeFail(["Unable to create temp directory", dir], output, 32);
2488
+ if (dir !== VALUES["temp.dir"]) {
2489
+ VALUES["temp.dir"] = dir;
2490
+ modified = true;
2497
2491
  }
2498
- } while ((dir !== "tmp") && (dir = "tmp"));
2499
- if (modified) {
2500
- this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2492
+ (0, types_1.setTempDir)(TEMP_DIR = output);
2493
+ break;
2501
2494
  }
2502
- settings.temp_dir = dir;
2503
- if ((0, types_1.isPlainObject)(temp)) {
2504
- temp.dir = dir;
2495
+ if (output instanceof Error) {
2496
+ this.writeFail(["Unable to create temp directory", dir], output, 32);
2505
2497
  }
2498
+ } while ((dir !== "tmp") && (dir = "tmp"));
2499
+ if (modified) {
2500
+ this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2501
+ }
2502
+ settings.temp_dir = dir;
2503
+ if ((0, types_1.isPlainObject)(temp)) {
2504
+ temp.dir = dir;
2506
2505
  }
2507
2506
  return true;
2508
2507
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
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": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.8.10",
23
+ "@e-mc/types": "0.8.12",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",