@e-mc/module 0.7.10 → 0.7.11

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 (2) hide show
  1. package/index.js +18 -24
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -586,7 +586,7 @@ class Module extends EventEmitter {
586
586
  this[_f] = new AbortController();
587
587
  this[_g] = null;
588
588
  }
589
- static get VERSION() { return "0.7.10"; }
589
+ static get VERSION() { return "0.7.11"; }
590
590
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
591
591
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
592
592
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -1097,40 +1097,34 @@ class Module extends EventEmitter {
1097
1097
  }
1098
1098
  return cacheKey ? (0, types_1.generateUUID)() : '';
1099
1099
  }
1100
- static asHash(data, algorithm, minLength = 0) {
1101
- if (!algorithm && !minLength) {
1100
+ static asHash(data, algorithm, digest) {
1101
+ if (!algorithm && !digest) {
1102
1102
  return crypto.createHash("sha256").update(data).digest("hex");
1103
1103
  }
1104
- let options, digest;
1105
- if (typeof minLength !== 'number') {
1106
- options = minLength;
1107
- minLength = 0;
1108
- }
1109
- if (typeof algorithm === 'number') {
1110
- minLength = algorithm;
1111
- algorithm = undefined;
1112
- }
1113
- else if ((0, types_1.isObject)(algorithm)) {
1114
- options = algorithm;
1115
- algorithm = undefined;
1116
- }
1117
- if (options) {
1118
- options = { ...options };
1119
- if ('minLength' in options) {
1120
- minLength = options.minLength;
1121
- delete options.minLength;
1122
- }
1104
+ let options;
1105
+ if ((0, types_1.isObject)(algorithm)) {
1106
+ options = { ...algorithm };
1123
1107
  if ('algorithm' in options) {
1124
1108
  algorithm = options.algorithm;
1125
1109
  delete options.algorithm;
1126
1110
  }
1111
+ else {
1112
+ algorithm = undefined;
1113
+ }
1127
1114
  if ('digest' in options) {
1128
1115
  digest = options.digest;
1129
1116
  delete options.digest;
1130
1117
  }
1118
+ else {
1119
+ digest = undefined;
1120
+ }
1121
+ }
1122
+ else if ((0, types_1.isObject)(digest)) {
1123
+ options = digest;
1124
+ digest = undefined;
1131
1125
  }
1132
- if (minLength > 0 && typeof data === 'string' && data.length > minLength) {
1133
- return data;
1126
+ else if (typeof digest !== 'string') {
1127
+ digest = undefined;
1134
1128
  }
1135
1129
  try {
1136
1130
  return crypto.createHash(algorithm || "sha256", options).update(data).digest(digest || "hex");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
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.10",
23
+ "@e-mc/types": "0.7.11",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",