@e-mc/module 0.9.6 → 0.9.7

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 -10
  2. package/index.js +18 -24
  3. package/package.json +2 -2
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.9.6/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.7/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -177,10 +177,8 @@ interface ModuleConstructor {
177
177
  parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
178
178
  parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
179
179
  asString(value: unknown, cacheKey?: boolean | "throws"): string;
180
- asHash(data: BinaryLike, minLength: number): string;
181
- asHash(data: BinaryLike, algorithm: string, minLength?: number): string;
182
- asHash(data: BinaryLike, algorithm?: string, options?: AsHashOptions): string;
183
- asHash(data: BinaryLike, options?: AsHashOptions): string;
180
+ asHash(data: BinaryLike, options: AsHashOptions): string;
181
+ asHash(data: BinaryLike, algorithm?: unknown, digest?: unknown): string;
184
182
  readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
185
183
  toPosix(value: unknown, normalize: boolean): string;
186
184
  toPosix(value: unknown, filename?: string, normalize?: boolean): string;
@@ -391,11 +389,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
391
389
 
392
390
  ## References
393
391
 
394
- - https://www.unpkg.com/@e-mc/types@0.9.6/lib/core.d.ts
395
- - https://www.unpkg.com/@e-mc/types@0.9.6/lib/logger.d.ts
396
- - https://www.unpkg.com/@e-mc/types@0.9.6/lib/module.d.ts
397
- - https://www.unpkg.com/@e-mc/types@0.9.6/lib/node.d.ts
398
- - https://www.unpkg.com/@e-mc/types@0.9.6/lib/settings.d.ts
392
+ - https://www.unpkg.com/@e-mc/types@0.9.7/lib/core.d.ts
393
+ - https://www.unpkg.com/@e-mc/types@0.9.7/lib/logger.d.ts
394
+ - https://www.unpkg.com/@e-mc/types@0.9.7/lib/module.d.ts
395
+ - https://www.unpkg.com/@e-mc/types@0.9.7/lib/node.d.ts
396
+ - https://www.unpkg.com/@e-mc/types@0.9.7/lib/settings.d.ts
399
397
 
400
398
  * https://www.npmjs.com/package/@types/node
401
399
 
package/index.js CHANGED
@@ -722,7 +722,7 @@ class Module extends EventEmitter {
722
722
  this[_f] = new AbortController();
723
723
  this[_g] = null;
724
724
  }
725
- static get VERSION() { return "0.9.6"; }
725
+ static get VERSION() { return "0.9.7"; }
726
726
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
727
727
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
728
728
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -1240,40 +1240,34 @@ class Module extends EventEmitter {
1240
1240
  }
1241
1241
  return cacheKey ? (0, types_1.generateUUID)() : '';
1242
1242
  }
1243
- static asHash(data, algorithm, minLength = 0) {
1244
- if (!algorithm && !minLength) {
1243
+ static asHash(data, algorithm, digest) {
1244
+ if (!algorithm && !digest) {
1245
1245
  return crypto.createHash("sha256").update(data).digest("hex");
1246
1246
  }
1247
- let options, digest;
1248
- if (typeof minLength !== 'number') {
1249
- options = minLength;
1250
- minLength = 0;
1251
- }
1252
- if (typeof algorithm === 'number') {
1253
- minLength = algorithm;
1254
- algorithm = undefined;
1255
- }
1256
- else if ((0, types_1.isObject)(algorithm)) {
1257
- options = algorithm;
1258
- algorithm = undefined;
1259
- }
1260
- if (options) {
1261
- options = { ...options };
1262
- if ('minLength' in options) {
1263
- minLength = options.minLength;
1264
- delete options.minLength;
1265
- }
1247
+ let options;
1248
+ if ((0, types_1.isObject)(algorithm)) {
1249
+ options = { ...algorithm };
1266
1250
  if ('algorithm' in options) {
1267
1251
  algorithm = options.algorithm;
1268
1252
  delete options.algorithm;
1269
1253
  }
1254
+ else {
1255
+ algorithm = undefined;
1256
+ }
1270
1257
  if ('digest' in options) {
1271
1258
  digest = options.digest;
1272
1259
  delete options.digest;
1273
1260
  }
1261
+ else {
1262
+ digest = undefined;
1263
+ }
1264
+ }
1265
+ else if ((0, types_1.isObject)(digest)) {
1266
+ options = digest;
1267
+ digest = undefined;
1274
1268
  }
1275
- if (minLength > 0 && typeof data === 'string' && data.length > minLength) {
1276
- return data;
1269
+ else if (typeof digest !== 'string') {
1270
+ digest = undefined;
1277
1271
  }
1278
1272
  try {
1279
1273
  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.9.6",
3
+ "version": "0.9.7",
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": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.9.6",
23
+ "@e-mc/types": "0.9.7",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",