@e-mc/module 0.7.7 → 0.7.9

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/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
- Copyright 2024 An Pham
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
1
+ Copyright 2024 An Pham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
7
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
- # @e-mc/module
2
-
3
- PEP 402 - Forever Any Tomato
4
-
5
- ## LICENSE
6
-
1
+ # @e-mc/module
2
+
3
+ ## LICENSE
4
+
7
5
  MIT
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ModuleConstructor } from '../types/lib';
2
-
3
- declare const Module: ModuleConstructor;
4
-
1
+ import type { ModuleConstructor } from '../types/lib';
2
+
3
+ declare const Module: ModuleConstructor;
4
+
5
5
  export = Module;
package/index.js CHANGED
@@ -117,6 +117,25 @@ const VALUES = {
117
117
  ["logger.level"]: -1
118
118
  };
119
119
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
120
+ const RESERVED_SHELL = [
121
+ 'if',
122
+ 'then',
123
+ 'elif',
124
+ 'else',
125
+ 'fi',
126
+ 'time',
127
+ 'for',
128
+ 'in',
129
+ 'until',
130
+ 'while',
131
+ 'do',
132
+ 'done',
133
+ 'case',
134
+ 'esac',
135
+ 'coproc',
136
+ 'select',
137
+ 'function'
138
+ ];
120
139
  let LOG_NEWLINE = true;
121
140
  let LOG_EMPTYLINE = false;
122
141
  let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
@@ -152,7 +171,7 @@ function applyStyle(options, style) {
152
171
  }
153
172
  function checkColorOptions(type, settings, options) {
154
173
  var _h, _j, _k, _l;
155
- if (typeof settings !== 'object') {
174
+ if (!(0, types_1.isObject)(settings)) {
156
175
  return false;
157
176
  }
158
177
  let result = false;
@@ -499,14 +518,15 @@ function withinDir(value, base) {
499
518
  value = path.normalize(value);
500
519
  return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
501
520
  }
502
- function formatPercent(value, precision = 3) {
521
+ function formatPercent(value, precision) {
503
522
  if (value <= 0) {
504
523
  return '0%';
505
524
  }
506
- if (value === Math.floor(value)) {
525
+ if (value === (value | 0)) {
507
526
  return value + '00%';
508
527
  }
509
- return (value * 100).toPrecision(precision) + '%';
528
+ value *= 100;
529
+ return value.toPrecision(value < 1 ? 2 : precision) + '%';
510
530
  }
511
531
  function tryIncrementDir(value, increment) {
512
532
  const baseDir = trimDir(value);
@@ -559,7 +579,7 @@ class Module extends EventEmitter {
559
579
  this[_f] = new AbortController();
560
580
  this[_g] = null;
561
581
  }
562
- static get VERSION() { return "0.7.7"; }
582
+ static get VERSION() { return "0.7.9"; }
563
583
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
564
584
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
565
585
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -847,10 +867,14 @@ class Module extends EventEmitter {
847
867
  ({ color: hintColor, bgColor: hintBgColor } = formatHint);
848
868
  hintBold !== null && hintBold !== void 0 ? hintBold : (hintBold = formatHint.bold);
849
869
  }
850
- value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
851
- }
852
- else if (title) {
853
870
  value = getValue();
871
+ hint = coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`;
872
+ }
873
+ else {
874
+ if (title) {
875
+ value = getValue();
876
+ }
877
+ hint = '';
854
878
  }
855
879
  const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
856
880
  const getMessage = (m, u) => type & 256 && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
@@ -895,19 +919,19 @@ class Module extends EventEmitter {
895
919
  }
896
920
  }
897
921
  else {
898
- if (!i) {
922
+ if (!i && !hint) {
899
923
  v = v.trim();
900
924
  }
901
925
  m = '';
902
926
  }
903
- output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
927
+ output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + hint + (i ? i : ' ') + m;
904
928
  }
905
929
  catch {
906
930
  }
907
931
  }
908
932
  if (!output) {
909
- const m = truncateStart(this.asString(message), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
910
- output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
933
+ const m = truncateStart(stripansi(this.asString(message)), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
934
+ output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + stripansi(hint) + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
911
935
  }
912
936
  if (broadcastId) {
913
937
  if (BROADCAST_OUT) {
@@ -1612,7 +1636,7 @@ class Module extends EventEmitter {
1612
1636
  const usage = user + system;
1613
1637
  result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
1614
1638
  }
1615
- return format ? formatPercent(result) : result;
1639
+ return format ? formatPercent(result, 3) : result;
1616
1640
  }
1617
1641
  }
1618
1642
  return format ? '' : 0;
@@ -1642,7 +1666,7 @@ class Module extends EventEmitter {
1642
1666
  return (0, types_1.formatSize)(result, { unit });
1643
1667
  }
1644
1668
  }
1645
- return format ? formatPercent(result / MEM_TOTAL) : result;
1669
+ return format ? formatPercent(result / MEM_TOTAL, 3) : result;
1646
1670
  }
1647
1671
  static formatCpuMem(start, all) {
1648
1672
  let cpu, cpu_bar, cpu_single_core, mem, mem_format;
@@ -1673,7 +1697,7 @@ class Module extends EventEmitter {
1673
1697
  }
1674
1698
  const unit = Math.max(bar, 10);
1675
1699
  const length = Math.floor(usage * unit);
1676
- const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
1700
+ const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
1677
1701
  result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
1678
1702
  }
1679
1703
  else if (usage) {
@@ -1683,7 +1707,7 @@ class Module extends EventEmitter {
1683
1707
  if (mem || all) {
1684
1708
  const usage = this.getMemUsage(mem_format || true);
1685
1709
  if (usage) {
1686
- result += (result ? ' ' : '') + usage + ' MEM';
1710
+ result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
1687
1711
  }
1688
1712
  }
1689
1713
  return result;
@@ -1921,6 +1945,9 @@ class Module extends EventEmitter {
1921
1945
  value = "'" + value.replace(/'/g, "'\\''") + "'";
1922
1946
  }
1923
1947
  }
1948
+ else if (RESERVED_SHELL.includes(value)) {
1949
+ value = "'" + value + "'";
1950
+ }
1924
1951
  }
1925
1952
  }
1926
1953
  else if (opt) {
@@ -2219,53 +2246,51 @@ class Module extends EventEmitter {
2219
2246
  });
2220
2247
  }
2221
2248
  }
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"];
2249
+ let dir = settings.temp_dir, write;
2250
+ if ((0, types_1.isPlainObject)(temp)) {
2251
+ dir || (dir = temp.dir);
2252
+ write = temp.write;
2253
+ }
2254
+ let modified;
2255
+ if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
2256
+ if (withinDir(dir, PROCESS_CWD)) {
2257
+ dir = dir.substring(ensureDir(PROCESS_CWD).length);
2240
2258
  }
2241
- if (typeof write === 'boolean') {
2242
- modified = VALUES["temp.write"] !== write;
2243
- VALUES["temp.write"] = write;
2259
+ else {
2260
+ this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
2261
+ dir = undefined;
2244
2262
  }
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;
2263
+ }
2264
+ if (!(0, types_1.isString)(dir)) {
2265
+ dir = VALUES["temp.dir"];
2266
+ }
2267
+ if (typeof write === 'boolean') {
2268
+ modified = VALUES["temp.write"] !== write;
2269
+ VALUES["temp.write"] = write;
2270
+ }
2271
+ do {
2272
+ const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
2273
+ if ((0, types_1.isString)(output)) {
2274
+ if (index > 0) {
2275
+ dir = trimDir(dir) + '_' + index;
2257
2276
  }
2258
- if (output instanceof Error) {
2259
- this.writeFail(["Unable to create temp directory", dir], output, 32);
2277
+ if (dir !== VALUES["temp.dir"]) {
2278
+ VALUES["temp.dir"] = dir;
2279
+ modified = true;
2260
2280
  }
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 });
2281
+ (0, types_1.setTempDir)(TEMP_DIR = output);
2282
+ break;
2264
2283
  }
2265
- settings.temp_dir = dir;
2266
- if ((0, types_1.isPlainObject)(temp)) {
2267
- temp.dir = dir;
2284
+ if (output instanceof Error) {
2285
+ this.writeFail(["Unable to create temp directory", dir], output, 32);
2268
2286
  }
2287
+ } while ((dir !== "tmp") && (dir = "tmp"));
2288
+ if (modified) {
2289
+ this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2290
+ }
2291
+ settings.temp_dir = dir;
2292
+ if ((0, types_1.isPlainObject)(temp)) {
2293
+ temp.dir = dir;
2269
2294
  }
2270
2295
  return true;
2271
2296
  }
package/lib-v4.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { IModuleLibV4 } from '../types/lib/compat-v4';
2
-
3
- declare const LibV4: IModuleLibV4;
4
-
1
+ import type { IModuleLibV4 } from '../types/lib/compat-v4';
2
+
3
+ declare const LibV4: IModuleLibV4;
4
+
5
5
  export = LibV4;
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "name": "@e-mc/module",
3
- "version": "0.7.7",
4
- "description": "Module base class for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/module"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/types": "0.7.7",
24
- "abort-controller": "^3.0.0",
25
- "chalk": "4.1.2",
26
- "event-target-shim": "^5.0.1",
27
- "file-type": "16.5.4",
28
- "mime-types": "^2.1.35",
29
- "strip-ansi": "6.0.1"
30
- }
31
- }
1
+ {
2
+ "name": "@e-mc/module",
3
+ "version": "0.7.9",
4
+ "description": "Module base class for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/module"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/types": "0.7.9",
24
+ "abort-controller": "^3.0.0",
25
+ "chalk": "4.1.2",
26
+ "event-target-shim": "^5.0.1",
27
+ "file-type": "16.5.4",
28
+ "mime-types": "^2.1.35",
29
+ "strip-ansi": "6.0.1"
30
+ }
31
+ }