Skip to content

Commit b9a9336

Browse files
committed
change default exports for classes to just regular exports for compat
1 parent 1b3706a commit b9a9336

File tree

5 files changed

+23
-43
lines changed

5 files changed

+23
-43
lines changed

lib/getHashDigest.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ function encodeBufferToBase(
6262
}
6363

6464
let crypto: typeof import("crypto");
65-
let createXXHash64: typeof import("./hash/xxhash64").default;
66-
let createMd4: typeof import("./hash/md4").default;
67-
let BatchedHash: typeof import("./hash/BatchedHash").default;
68-
let BulkUpdateDecorator: typeof import("./hash/BulkUpdateDecorator").default;
65+
let createXXHash64: typeof import("./hash/xxhash64").create;
66+
let createMd4: typeof import("./hash/md4").create;
67+
let BatchedHash: typeof import("./hash/BatchedHash").BatchedHash;
68+
let BulkUpdateDecorator: typeof import("./hash/BulkUpdateDecorator").BulkUpdateDecorator;
6969

7070
export default function getHashDigest(
7171
buffer: Buffer,
@@ -80,20 +80,20 @@ export default function getHashDigest(
8080

8181
if (algorithm === "xxhash64") {
8282
if (createXXHash64 === undefined) {
83-
createXXHash64 = require("./hash/xxhash64").default;
83+
createXXHash64 = require("./hash/xxhash64").create;
8484

8585
if (BatchedHash === undefined) {
86-
BatchedHash = require("./hash/BatchedHash").default;
86+
BatchedHash = require("./hash/BatchedHash").BatchedHash;
8787
}
8888
}
8989

9090
hash = new BatchedHash(createXXHash64() as unknown as Hash);
9191
} else if (algorithm === "md4") {
9292
if (createMd4 === undefined) {
93-
createMd4 = require("./hash/md4").default;
93+
createMd4 = require("./hash/md4").create;
9494

9595
if (BatchedHash === undefined) {
96-
BatchedHash = require("./hash/BatchedHash").default;
96+
BatchedHash = require("./hash/BatchedHash").BatchedHash;
9797
}
9898
}
9999

@@ -103,7 +103,8 @@ export default function getHashDigest(
103103
crypto = require("crypto");
104104

105105
if (BulkUpdateDecorator === undefined) {
106-
BulkUpdateDecorator = require("./hash/BulkUpdateDecorator").default;
106+
BulkUpdateDecorator =
107+
require("./hash/BulkUpdateDecorator").BulkUpdateDecorator;
107108
}
108109
}
109110

@@ -113,7 +114,8 @@ export default function getHashDigest(
113114
crypto = require("crypto");
114115

115116
if (BulkUpdateDecorator === undefined) {
116-
BulkUpdateDecorator = require("./hash/BulkUpdateDecorator").default;
117+
BulkUpdateDecorator =
118+
require("./hash/BulkUpdateDecorator").BulkUpdateDecorator;
117119
}
118120
}
119121

lib/hash/BatchedHash.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Hash, Encoding, BinaryToTextEncoding } from "crypto";
22
import { MAX_SHORT_STRING } from "./wasm-hash";
33

4-
export default class BatchedHash {
4+
export class BatchedHash {
55
public string?: string;
66
public encoding?: Encoding;
77
public readonly hash: Hash;
@@ -12,12 +12,7 @@ export default class BatchedHash {
1212
this.hash = hash;
1313
}
1414

15-
/**
16-
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
17-
* @param {string|Buffer} data data
18-
* @param {string=} inputEncoding data encoding
19-
* @returns {this} updated hash
20-
*/
15+
// Updates the hash https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding
2116
update(data: string | Buffer, inputEncoding?: Encoding): this {
2217
if (this.string !== undefined) {
2318
if (
@@ -61,11 +56,7 @@ export default class BatchedHash {
6156
return this;
6257
}
6358

64-
/**
65-
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
66-
* @param {string=} encoding encoding of the return value
67-
* @returns {string|Buffer} digest
68-
*/
59+
// Calculates the digest https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding
6960
digest(encoding?: BinaryToTextEncoding): string | Buffer {
7061
if (this.string !== undefined) {
7162
if (this.encoding !== undefined) {

lib/hash/BulkUpdateDecorator.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ const BULK_SIZE = 2000;
55

66
// We are using an object instead of a Map as this will stay static during the runtime
77
// so access to it can be optimized by v8
8-
const digestCaches: { [key: string]: any } = {};
8+
const digestCaches: Record<string, any> = {};
99

10-
export default class BulkUpdateDecorator {
11-
/**
12-
* @param {HashOrFactory} hashOrFactory function to create a hash
13-
* @param {string=} hashKey key for caching
14-
*/
10+
export class BulkUpdateDecorator {
1511
hash?: Hash;
1612
hashFactory?: () => Hash;
1713
hashKey: string;
@@ -31,12 +27,7 @@ export default class BulkUpdateDecorator {
3127
this.buffer = "";
3228
}
3329

34-
/**
35-
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
36-
* @param {string|Buffer} data data
37-
* @param {string=} inputEncoding data encoding
38-
* @returns {this} updated hash
39-
*/
30+
// Updates the hash https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding
4031
update(data: string | Buffer, inputEncoding?: Encoding): this {
4132
if (
4233
inputEncoding !== undefined ||
@@ -75,11 +66,7 @@ export default class BulkUpdateDecorator {
7566
return this;
7667
}
7768

78-
/**
79-
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
80-
* @param {string=} encoding encoding of the return value
81-
* @returns {string|Buffer} digest
82-
*/
69+
// Calculates the digest https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding
8370
digest(encoding?: BinaryToTextEncoding): string | Buffer {
8471
let digestCache;
8572
let digestResult: string | Buffer;

lib/hash/md4.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Author Tobias Koppers @sokra
44
*/
55

6-
import { create } from "./wasm-hash";
6+
import { create as createFn } from "./wasm-hash";
77

88
//#region wasm code: md4 (../../../assembly/hash/md4.asm.ts) --initialMemory 1
99
const md4 = new WebAssembly.Module(
@@ -15,4 +15,4 @@ const md4 = new WebAssembly.Module(
1515
);
1616
//#endregion
1717

18-
export default create.bind(null, md4, [], 64, 32);
18+
export const create = createFn.bind(null, md4, [], 64, 32);

lib/hash/xxhash64.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
import { create } from "./wasm-hash";
5+
import { create as createFn } from "./wasm-hash";
66

77
//#region wasm code: xxhash64 (../../../assembly/hash/xxhash64.asm.ts) --initialMemory 1
88
const xxhash64 = new WebAssembly.Module(
@@ -14,4 +14,4 @@ const xxhash64 = new WebAssembly.Module(
1414
);
1515
//#endregion
1616

17-
export default create.bind(null, xxhash64, [], 32, 16);
17+
export const create = createFn.bind(null, xxhash64, [], 32, 16);

0 commit comments

Comments
 (0)