@e-mc/module 0.12.3 → 0.12.5

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 +8 -8
  2. package/index.js +16 -10
  3. package/package.json +4 -5
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.2/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.5/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -224,8 +224,8 @@ interface ModuleConstructor {
224
224
  initCpuUsage(instance?: IModule): CpuUsage;
225
225
  getCpuUsage(start: CpuUsage, format: true): string;
226
226
  getCpuUsage(start: CpuUsage, format?: boolean): number;
227
- getMemUsage(format: true): string;
228
- getMemUsage(format?: boolean): number;
227
+ getMemUsage(format: true | "%" | "b" | "gb" | "kb" | "mb" | "pb" | "tb" | "B" | "GB" | "KB" | "MB" | "PB" | "TB", free?: boolean): string;
228
+ getMemUsage(format?: boolean, free?: boolean): number;
229
229
  formatCpuMem(start: CpuUsage, all?: boolean): string;
230
230
  getPackageVersion(name: string | [string, string], options?: PackageVersionOptions): string;
231
231
  checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
@@ -414,11 +414,11 @@ interface LoggerModule {
414
414
 
415
415
  ## References
416
416
 
417
- - https://www.unpkg.com/@e-mc/types@0.12.2/lib/core.d.ts
418
- - https://www.unpkg.com/@e-mc/types@0.12.2/lib/logger.d.ts
419
- - https://www.unpkg.com/@e-mc/types@0.12.2/lib/module.d.ts
420
- - https://www.unpkg.com/@e-mc/types@0.12.2/lib/node.d.ts
421
- - https://www.unpkg.com/@e-mc/types@0.12.2/lib/settings.d.ts
417
+ - https://www.unpkg.com/@e-mc/types@0.12.5/lib/core.d.ts
418
+ - https://www.unpkg.com/@e-mc/types@0.12.5/lib/logger.d.ts
419
+ - https://www.unpkg.com/@e-mc/types@0.12.5/lib/module.d.ts
420
+ - https://www.unpkg.com/@e-mc/types@0.12.5/lib/node.d.ts
421
+ - https://www.unpkg.com/@e-mc/types@0.12.5/lib/settings.d.ts
422
422
 
423
423
  * https://www.npmjs.com/package/@types/node
424
424
 
package/index.js CHANGED
@@ -89,7 +89,8 @@ const SETTINGS = {
89
89
  cpu_bar_color: ['bgBlue', 'bgYellow', 'bgRed'],
90
90
  cpu_single_core: true,
91
91
  mem: true,
92
- mem_format: '%'
92
+ mem_format: '%',
93
+ mem_free: false
93
94
  },
94
95
  image: true,
95
96
  compress: true,
@@ -868,7 +869,7 @@ class Module extends EventEmitter {
868
869
  static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
869
870
  static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
870
871
  static get VERSION() {
871
- return "0.12.3";
872
+ return "0.12.5";
872
873
  }
873
874
  static get LOG_TYPE() {
874
875
  return types_1.LOG_TYPE;
@@ -2031,15 +2032,20 @@ class Module extends EventEmitter {
2031
2032
  }
2032
2033
  return format ? '' : 0;
2033
2034
  }
2034
- static getMemUsage(format) {
2035
+ static getMemUsage(format, free) {
2035
2036
  if (!VALUES["node.process.memory_usage"]) {
2036
2037
  return format ? '' : 0;
2037
2038
  }
2038
- const usage = process.memoryUsage();
2039
2039
  let result = 0;
2040
- for (const name in usage) {
2041
- if (name !== 'heapUsed') {
2042
- result += usage[name];
2040
+ if (free) {
2041
+ result = os.freemem();
2042
+ }
2043
+ else {
2044
+ const usage = process.memoryUsage();
2045
+ for (const name in usage) {
2046
+ if (name !== 'heapUsed') {
2047
+ result += usage[name];
2048
+ }
2043
2049
  }
2044
2050
  }
2045
2051
  if (typeof format === 'string' && format !== '%') {
@@ -2059,9 +2065,9 @@ class Module extends EventEmitter {
2059
2065
  return format ? formatPercent(result / MEM_TOTAL, 3) : result;
2060
2066
  }
2061
2067
  static formatCpuMem(start, all) {
2062
- let cpu, cpu_bar, cpu_single_core, mem, mem_format;
2068
+ let cpu, cpu_bar, cpu_single_core, mem, mem_format, mem_free;
2063
2069
  if (SETTINGS.process.enabled !== false) {
2064
- ({ cpu, cpu_bar, cpu_single_core, mem, mem_format } = SETTINGS.process);
2070
+ ({ cpu, cpu_bar, cpu_single_core, mem, mem_format, mem_free } = SETTINGS.process);
2065
2071
  }
2066
2072
  let result = '';
2067
2073
  if (cpu || all) {
@@ -2096,7 +2102,7 @@ class Module extends EventEmitter {
2096
2102
  }
2097
2103
  if (mem || all) {
2098
2104
  const format = mem_format || '%';
2099
- const usage = this.getMemUsage(format);
2105
+ const usage = this.getMemUsage(format, mem_free);
2100
2106
  if (usage) {
2101
2107
  result += (result ? ' ' : '') + usage + (format === '%' ? ' MEM' : '');
2102
2108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.12.3",
3
+ "version": "0.12.5",
4
4
  "description": "Module base class for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -13,18 +13,17 @@
13
13
  "directory": "src/module"
14
14
  },
15
15
  "keywords": [
16
- "squared",
17
- "squared-functions"
16
+ "squared"
18
17
  ],
19
18
  "author": "An Pham <anpham6@gmail.com>",
20
19
  "license": "BSD-3-Clause",
21
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
21
  "dependencies": {
23
- "@e-mc/types": "0.12.3",
22
+ "@e-mc/types": "0.12.5",
24
23
  "chalk": "4.1.2",
25
24
  "file-type": "^18.7.0",
26
25
  "js-yaml": "^4.1.0",
27
26
  "mime-types": "^2.1.35",
28
- "picomatch": "^4.0.2"
27
+ "picomatch": "^4.0.3"
29
28
  }
30
29
  }