@e-mc/module 0.7.7 → 0.7.8

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 +0 -2
  2. package/index.js +49 -50
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # @e-mc/module
2
2
 
3
- PEP 402 - Forever Any Tomato
4
-
5
3
  ## LICENSE
6
4
 
7
5
  MIT
package/index.js CHANGED
@@ -152,7 +152,7 @@ function applyStyle(options, style) {
152
152
  }
153
153
  function checkColorOptions(type, settings, options) {
154
154
  var _h, _j, _k, _l;
155
- if (typeof settings !== 'object') {
155
+ if (!(0, types_1.isObject)(settings)) {
156
156
  return false;
157
157
  }
158
158
  let result = false;
@@ -499,14 +499,15 @@ function withinDir(value, base) {
499
499
  value = path.normalize(value);
500
500
  return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
501
501
  }
502
- function formatPercent(value, precision = 3) {
502
+ function formatPercent(value, precision) {
503
503
  if (value <= 0) {
504
504
  return '0%';
505
505
  }
506
- if (value === Math.floor(value)) {
506
+ if (value === (value | 0)) {
507
507
  return value + '00%';
508
508
  }
509
- return (value * 100).toPrecision(precision) + '%';
509
+ value *= 100;
510
+ return value.toPrecision(value < 1 ? 2 : precision) + '%';
510
511
  }
511
512
  function tryIncrementDir(value, increment) {
512
513
  const baseDir = trimDir(value);
@@ -559,7 +560,7 @@ class Module extends EventEmitter {
559
560
  this[_f] = new AbortController();
560
561
  this[_g] = null;
561
562
  }
562
- static get VERSION() { return "0.7.7"; }
563
+ static get VERSION() { return "0.7.8"; }
563
564
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
564
565
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
565
566
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -1612,7 +1613,7 @@ class Module extends EventEmitter {
1612
1613
  const usage = user + system;
1613
1614
  result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
1614
1615
  }
1615
- return format ? formatPercent(result) : result;
1616
+ return format ? formatPercent(result, 3) : result;
1616
1617
  }
1617
1618
  }
1618
1619
  return format ? '' : 0;
@@ -1642,7 +1643,7 @@ class Module extends EventEmitter {
1642
1643
  return (0, types_1.formatSize)(result, { unit });
1643
1644
  }
1644
1645
  }
1645
- return format ? formatPercent(result / MEM_TOTAL) : result;
1646
+ return format ? formatPercent(result / MEM_TOTAL, 3) : result;
1646
1647
  }
1647
1648
  static formatCpuMem(start, all) {
1648
1649
  let cpu, cpu_bar, cpu_single_core, mem, mem_format;
@@ -1673,7 +1674,7 @@ class Module extends EventEmitter {
1673
1674
  }
1674
1675
  const unit = Math.max(bar, 10);
1675
1676
  const length = Math.floor(usage * unit);
1676
- const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
1677
+ const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
1677
1678
  result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
1678
1679
  }
1679
1680
  else if (usage) {
@@ -1683,7 +1684,7 @@ class Module extends EventEmitter {
1683
1684
  if (mem || all) {
1684
1685
  const usage = this.getMemUsage(mem_format || true);
1685
1686
  if (usage) {
1686
- result += (result ? ' ' : '') + usage + ' MEM';
1687
+ result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
1687
1688
  }
1688
1689
  }
1689
1690
  return result;
@@ -2219,53 +2220,51 @@ class Module extends EventEmitter {
2219
2220
  });
2220
2221
  }
2221
2222
  }
2222
- {
2223
- let dir = settings.temp_dir, write;
2224
- if ((0, types_1.isPlainObject)(temp)) {
2225
- dir || (dir = temp.dir);
2226
- write = temp.write;
2227
- }
2228
- let modified;
2229
- if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
2230
- if (withinDir(dir, PROCESS_CWD)) {
2231
- dir = dir.substring(ensureDir(PROCESS_CWD).length);
2232
- }
2233
- else {
2234
- this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
2235
- dir = undefined;
2236
- }
2237
- }
2238
- if (!(0, types_1.isString)(dir)) {
2239
- dir = VALUES["temp.dir"];
2223
+ let dir = settings.temp_dir, write;
2224
+ if ((0, types_1.isPlainObject)(temp)) {
2225
+ dir || (dir = temp.dir);
2226
+ write = temp.write;
2227
+ }
2228
+ let modified;
2229
+ if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
2230
+ if (withinDir(dir, PROCESS_CWD)) {
2231
+ dir = dir.substring(ensureDir(PROCESS_CWD).length);
2240
2232
  }
2241
- if (typeof write === 'boolean') {
2242
- modified = VALUES["temp.write"] !== write;
2243
- VALUES["temp.write"] = write;
2233
+ else {
2234
+ this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
2235
+ dir = undefined;
2244
2236
  }
2245
- do {
2246
- const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
2247
- if ((0, types_1.isString)(output)) {
2248
- if (index > 0) {
2249
- dir = trimDir(dir) + '_' + index;
2250
- }
2251
- if (dir !== VALUES["temp.dir"]) {
2252
- VALUES["temp.dir"] = dir;
2253
- modified = true;
2254
- }
2255
- (0, types_1.setTempDir)(TEMP_DIR = output);
2256
- break;
2237
+ }
2238
+ if (!(0, types_1.isString)(dir)) {
2239
+ dir = VALUES["temp.dir"];
2240
+ }
2241
+ if (typeof write === 'boolean') {
2242
+ modified = VALUES["temp.write"] !== write;
2243
+ VALUES["temp.write"] = write;
2244
+ }
2245
+ do {
2246
+ const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
2247
+ if ((0, types_1.isString)(output)) {
2248
+ if (index > 0) {
2249
+ dir = trimDir(dir) + '_' + index;
2257
2250
  }
2258
- if (output instanceof Error) {
2259
- this.writeFail(["Unable to create temp directory", dir], output, 32);
2251
+ if (dir !== VALUES["temp.dir"]) {
2252
+ VALUES["temp.dir"] = dir;
2253
+ modified = true;
2260
2254
  }
2261
- } while ((dir !== "tmp") && (dir = "tmp"));
2262
- if (modified) {
2263
- this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2255
+ (0, types_1.setTempDir)(TEMP_DIR = output);
2256
+ break;
2264
2257
  }
2265
- settings.temp_dir = dir;
2266
- if ((0, types_1.isPlainObject)(temp)) {
2267
- temp.dir = dir;
2258
+ if (output instanceof Error) {
2259
+ this.writeFail(["Unable to create temp directory", dir], output, 32);
2268
2260
  }
2261
+ } while ((dir !== "tmp") && (dir = "tmp"));
2262
+ if (modified) {
2263
+ this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2264
+ }
2265
+ settings.temp_dir = dir;
2266
+ if ((0, types_1.isPlainObject)(temp)) {
2267
+ temp.dir = dir;
2269
2268
  }
2270
2269
  return true;
2271
2270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
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.7.7",
23
+ "@e-mc/types": "0.7.8",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",