@e-mc/module 0.5.5 → 0.5.6

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/LICENSE +1 -1
  2. package/index.js +31 -26
  3. package/package.json +2 -2
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Anya Forger
1
+ Copyright 2024 An Pham
2
2
 
3
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
4
 
package/index.js CHANGED
@@ -144,12 +144,14 @@ const YARN_VER = (function () {
144
144
  })();
145
145
  function applyStyle(options, style) {
146
146
  var _h;
147
+ var _j;
147
148
  for (const attr in style) {
148
- (_h = options)[attr] ?? (_h[attr] = style[attr]);
149
+ (_h = (_j = options)[attr]) !== null && _h !== void 0 ? _h : (_j[attr] = style[attr]);
149
150
  }
150
151
  return options;
151
152
  }
152
153
  function checkColorOptions(type, settings, options) {
154
+ var _h, _j, _k, _l;
153
155
  if (typeof settings !== 'object') {
154
156
  return false;
155
157
  }
@@ -163,7 +165,7 @@ function checkColorOptions(type, settings, options) {
163
165
  result = true;
164
166
  }
165
167
  if (typeof settings.valueBold === 'boolean') {
166
- options.valueBold ?? (options.valueBold = settings.valueBold);
168
+ (_h = options.valueBold) !== null && _h !== void 0 ? _h : (options.valueBold = settings.valueBold);
167
169
  }
168
170
  if (settings.hintColor) {
169
171
  options.hintColor || (options.hintColor = settings.hintColor);
@@ -174,7 +176,7 @@ function checkColorOptions(type, settings, options) {
174
176
  result = true;
175
177
  }
176
178
  if (typeof settings.hintBold === 'boolean') {
177
- options.hintBold ?? (options.hintBold = settings.hintBold);
179
+ (_j = options.hintBold) !== null && _j !== void 0 ? _j : (options.hintBold = settings.hintBold);
178
180
  }
179
181
  if (type & types_1.LOG_TYPE.FAIL) {
180
182
  return result;
@@ -188,7 +190,7 @@ function checkColorOptions(type, settings, options) {
188
190
  result = true;
189
191
  }
190
192
  if (typeof settings.titleBold === 'boolean') {
191
- options.titleBold ?? (options.titleBold = settings.titleBold);
193
+ (_k = options.titleBold) !== null && _k !== void 0 ? _k : (options.titleBold = settings.titleBold);
192
194
  }
193
195
  if (settings.messageColor) {
194
196
  options.messageColor || (options.messageColor = settings.messageColor);
@@ -199,7 +201,7 @@ function checkColorOptions(type, settings, options) {
199
201
  result = true;
200
202
  }
201
203
  if (typeof settings.messageBold === 'boolean') {
202
- options.messageBold ?? (options.messageBold = settings.messageBold);
204
+ (_l = options.messageBold) !== null && _l !== void 0 ? _l : (options.messageBold = settings.messageBold);
203
205
  }
204
206
  return result;
205
207
  }
@@ -397,7 +399,7 @@ function checkFunction(value) {
397
399
  }
398
400
  function encryptMessage(data, cipher, algorithm) {
399
401
  var _h;
400
- if (cipher?.key && cipher.iv) {
402
+ if ((cipher === null || cipher === void 0 ? void 0 : cipher.key) && cipher.iv) {
401
403
  if (!algorithm) {
402
404
  algorithm = cipher.algorithm || 'aes-256-gcm';
403
405
  }
@@ -458,7 +460,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
458
460
  }
459
461
  else if (options.hostPermissionOnly) {
460
462
  const host = this.host;
461
- if (host?.permission && !host[method](result)) {
463
+ if ((host === null || host === void 0 ? void 0 : host.permission) && !host[method](result)) {
462
464
  if (options.throwsPermission) {
463
465
  throw errorPermission(result);
464
466
  }
@@ -557,7 +559,7 @@ class Module extends EventEmitter {
557
559
  this[_f] = new AbortController();
558
560
  this[_g] = null;
559
561
  }
560
- static get VERSION() { return "0.5.5"; }
562
+ static get VERSION() { return "0.5.6"; }
561
563
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
562
564
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
563
565
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -636,6 +638,7 @@ class Module extends EventEmitter {
636
638
  return true;
637
639
  }
638
640
  static formatMessage(type, title, value, message, options = {}) {
641
+ var _h, _j, _k, _l;
639
642
  if (options.type) {
640
643
  type |= options.type;
641
644
  }
@@ -675,7 +678,7 @@ class Module extends EventEmitter {
675
678
  const titleIndent = options.titleIndent ? typeof options.titleIndent === 'number' ? Math.max(options.titleIndent, 0) : 0 : -1;
676
679
  let output, error, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512) || options.failed ? 'center' : formatTitle.justify);
677
680
  if (Array.isArray(value)) {
678
- hint = value[1] ?? '';
681
+ hint = (_h = value[1]) !== null && _h !== void 0 ? _h : '';
679
682
  value = value[0];
680
683
  }
681
684
  if (message && message instanceof Error) {
@@ -825,7 +828,7 @@ class Module extends EventEmitter {
825
828
  }
826
829
  }
827
830
  if (bold) {
828
- options.messageBold ?? (options.messageBold = true);
831
+ (_j = options.messageBold) !== null && _j !== void 0 ? _j : (options.messageBold = true);
829
832
  }
830
833
  }
831
834
  }
@@ -842,7 +845,7 @@ class Module extends EventEmitter {
842
845
  }
843
846
  if (!hintColor && !hintBgColor) {
844
847
  ({ color: hintColor, bgColor: hintBgColor } = formatHint);
845
- hintBold ?? (hintBold = formatHint.bold);
848
+ hintBold !== null && hintBold !== void 0 ? hintBold : (hintBold = formatHint.bold);
846
849
  }
847
850
  value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
848
851
  }
@@ -858,7 +861,7 @@ class Module extends EventEmitter {
858
861
  }
859
862
  if (!valueColor && !valueBgColor) {
860
863
  ({ color: valueColor, bgColor: valueBgColor } = formatValue);
861
- valueBold ?? (valueBold = formatValue.bold);
864
+ valueBold !== null && valueBold !== void 0 ? valueBold : (valueBold = formatValue.bold);
862
865
  }
863
866
  try {
864
867
  let v = value, i = id, m = message;
@@ -874,9 +877,9 @@ class Module extends EventEmitter {
874
877
  const formatMessage = format.message;
875
878
  if (!messageColor && !messageBgColor) {
876
879
  ({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
877
- messageBold ?? (messageBold = formatMessage.bold);
880
+ messageBold !== null && messageBold !== void 0 ? messageBold : (messageBold = formatMessage.bold);
878
881
  }
879
- messageWidth ?? (messageWidth = formatMessage.width);
882
+ messageWidth !== null && messageWidth !== void 0 ? messageWidth : (messageWidth = formatMessage.width);
880
883
  let u = unit;
881
884
  if (u) {
882
885
  if ((0, types_1.isObject)(SETTINGS.time_process)) {
@@ -897,13 +900,13 @@ class Module extends EventEmitter {
897
900
  }
898
901
  m = '';
899
902
  }
900
- output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (options.titleBold || formatTitle.bold) ?? false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
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;
901
904
  }
902
905
  catch {
903
906
  }
904
907
  }
905
908
  if (!output) {
906
- const m = truncateStart(this.asString(message), options.messageWidth ?? format.message.width);
909
+ const m = truncateStart(this.asString(message), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
907
910
  output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
908
911
  }
909
912
  if (broadcastId) {
@@ -1404,7 +1407,7 @@ class Module extends EventEmitter {
1404
1407
  }
1405
1408
  }
1406
1409
  if (isFile) {
1407
- if (ignoreFile?.test(name)) {
1410
+ if (ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.test(name)) {
1408
1411
  return ignore();
1409
1412
  }
1410
1413
  if (overwrite === false) {
@@ -1429,7 +1432,7 @@ class Module extends EventEmitter {
1429
1432
  }));
1430
1433
  }
1431
1434
  else if (depth > 0 && (isDir || file.isDirectory())) {
1432
- if (ignoreDir?.test(name)) {
1435
+ if (ignoreDir === null || ignoreDir === void 0 ? void 0 : ignoreDir.test(name)) {
1433
1436
  return ignore();
1434
1437
  }
1435
1438
  recurse.call(this, paths.concat(name), depth - 1);
@@ -1945,6 +1948,7 @@ class Module extends EventEmitter {
1945
1948
  }
1946
1949
  static loadSettings(settings, password) {
1947
1950
  var _h;
1951
+ var _j;
1948
1952
  const current = VALUES["process.password"];
1949
1953
  if (current) {
1950
1954
  const proc = settings.process || {};
@@ -1960,7 +1964,7 @@ class Module extends EventEmitter {
1960
1964
  }
1961
1965
  }
1962
1966
  else if ((0, types_1.isString)(password)) {
1963
- VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
1967
+ VALUES["process.password"] = encryptMessage(password, (_h = settings.process) === null || _h === void 0 ? void 0 : _h.cipher);
1964
1968
  }
1965
1969
  const { temp, node, permission, memory, error, logger } = settings;
1966
1970
  if ((0, types_1.isPlainObject)(node)) {
@@ -2006,7 +2010,7 @@ class Module extends EventEmitter {
2006
2010
  VALUES["process.env.apply"] = env.apply;
2007
2011
  }
2008
2012
  if ((0, types_1.isString)(pwd)) {
2009
- VALUES[_h = "process.password"] || (VALUES[_h] = encryptMessage(pwd, cipher));
2013
+ VALUES[_j = "process.password"] || (VALUES[_j] = encryptMessage(pwd, cipher));
2010
2014
  }
2011
2015
  }
2012
2016
  if (memory && (0, types_1.isPlainObject)(memory.settings)) {
@@ -2146,7 +2150,7 @@ class Module extends EventEmitter {
2146
2150
  break;
2147
2151
  }
2148
2152
  }
2149
- if (broadcast?.out) {
2153
+ if (broadcast === null || broadcast === void 0 ? void 0 : broadcast.out) {
2150
2154
  VALUES["broadcast.out"] = this.parseFunction(broadcast.out, { external: true, absolute: true });
2151
2155
  }
2152
2156
  if (stack_trace && stack_trace !== true && +stack_trace > 0) {
@@ -2242,7 +2246,7 @@ class Module extends EventEmitter {
2242
2246
  }
2243
2247
  const host = this.host;
2244
2248
  const item = this[kSupports][name];
2245
- return host && !item?.modified ? host.supports(name) : item?.value === true;
2249
+ return host && !(item === null || item === void 0 ? void 0 : item.modified) ? host.supports(name) : (item === null || item === void 0 ? void 0 : item.value) === true;
2246
2250
  }
2247
2251
  getTempDir(pathname, filename, createDir) {
2248
2252
  let increment = 0, moduleDir, uuidDir;
@@ -2266,11 +2270,11 @@ class Module extends EventEmitter {
2266
2270
  let result;
2267
2271
  if ((0, types_1.isString)(pathname)) {
2268
2272
  leading.push(pathname);
2269
- createDir ?? (createDir = true);
2273
+ createDir !== null && createDir !== void 0 ? createDir : (createDir = true);
2270
2274
  }
2271
2275
  if (uuidDir) {
2272
2276
  leading.push((0, types_1.generateUUID)());
2273
- createDir ?? (createDir = true);
2277
+ createDir !== null && createDir !== void 0 ? createDir : (createDir = true);
2274
2278
  }
2275
2279
  if ((createDir || increment > 0) && !Module.isDir(result = path.join(...leading))) {
2276
2280
  const [output] = tryIncrementDir(result, increment);
@@ -3204,8 +3208,9 @@ class Module extends EventEmitter {
3204
3208
  return !!this[kPermission];
3205
3209
  }
3206
3210
  isFatal(err) {
3207
- const fatal = this.host?.config.error?.fatal;
3208
- return fatal ?? VALUES["error.fatal"];
3211
+ var _h, _j;
3212
+ const fatal = (_j = (_h = this.host) === null || _h === void 0 ? void 0 : _h.config.error) === null || _j === void 0 ? void 0 : _j.fatal;
3213
+ return fatal !== null && fatal !== void 0 ? fatal : VALUES["error.fatal"];
3209
3214
  }
3210
3215
  get moduleName() {
3211
3216
  return this._moduleName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
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.5.5",
23
+ "@e-mc/types": "0.5.6",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",