@naturalcycles/nodejs-lib 13.11.0 → 13.13.0
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.
|
@@ -20,10 +20,21 @@ function sha256AsBuffer(s) {
|
|
|
20
20
|
}
|
|
21
21
|
exports.sha256AsBuffer = sha256AsBuffer;
|
|
22
22
|
function hash(s, algorithm, outputEncoding = 'hex') {
|
|
23
|
+
// todo: cleanup after @types/node is updated
|
|
24
|
+
// https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#crypto-implement-cryptohash
|
|
25
|
+
// Node 20.12+
|
|
26
|
+
if (node_crypto_1.default.hash) {
|
|
27
|
+
return node_crypto_1.default.hash(algorithm, s, outputEncoding);
|
|
28
|
+
}
|
|
23
29
|
return node_crypto_1.default.createHash(algorithm).update(s).digest(outputEncoding);
|
|
24
30
|
}
|
|
25
31
|
exports.hash = hash;
|
|
26
32
|
function hashAsBuffer(s, algorithm) {
|
|
33
|
+
// todo: cleanup after @types/node is updated
|
|
34
|
+
// Node 20.12+
|
|
35
|
+
if (node_crypto_1.default.hash) {
|
|
36
|
+
return node_crypto_1.default.hash(algorithm, s, 'buffer');
|
|
37
|
+
}
|
|
27
38
|
return node_crypto_1.default.createHash(algorithm).update(s).digest();
|
|
28
39
|
}
|
|
29
40
|
exports.hashAsBuffer = hashAsBuffer;
|
|
@@ -26,6 +26,16 @@ export interface ReadableTyped<T> extends Readable {
|
|
|
26
26
|
}
|
|
27
27
|
export interface WritableTyped<T> extends Writable {
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Type alias that indicates that the Readable is not in objectMode,
|
|
31
|
+
* e.g returns a binary stream (like a gzip stream).
|
|
32
|
+
*/
|
|
33
|
+
export type ReadableBinary = Readable;
|
|
34
|
+
/**
|
|
35
|
+
* Type alias that indicates that the Writable is not in objectMode,
|
|
36
|
+
* e.g reads a binary stream (like a gzip stream).
|
|
37
|
+
*/
|
|
38
|
+
export type WritableBinary = Writable;
|
|
29
39
|
export interface TransformTyped<IN, OUT> extends Transform {
|
|
30
40
|
}
|
|
31
41
|
export interface TransformOptions {
|
package/package.json
CHANGED
|
@@ -22,10 +22,23 @@ export function hash(
|
|
|
22
22
|
algorithm: string,
|
|
23
23
|
outputEncoding: BinaryToTextEncoding = 'hex',
|
|
24
24
|
): string {
|
|
25
|
+
// todo: cleanup after @types/node is updated
|
|
26
|
+
// https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#crypto-implement-cryptohash
|
|
27
|
+
// Node 20.12+
|
|
28
|
+
if ((crypto as any).hash) {
|
|
29
|
+
return (crypto as any).hash(algorithm, s, outputEncoding)
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
return crypto.createHash(algorithm).update(s).digest(outputEncoding)
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
export function hashAsBuffer(s: string | Buffer, algorithm: string): Buffer {
|
|
36
|
+
// todo: cleanup after @types/node is updated
|
|
37
|
+
// Node 20.12+
|
|
38
|
+
if ((crypto as any).hash) {
|
|
39
|
+
return (crypto as any).hash(algorithm, s, 'buffer')
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
return crypto.createHash(algorithm).update(s).digest()
|
|
30
43
|
}
|
|
31
44
|
|
|
@@ -48,6 +48,17 @@ export interface ReadableTyped<T> extends Readable {
|
|
|
48
48
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
49
49
|
export interface WritableTyped<T> extends Writable {}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Type alias that indicates that the Readable is not in objectMode,
|
|
53
|
+
* e.g returns a binary stream (like a gzip stream).
|
|
54
|
+
*/
|
|
55
|
+
export type ReadableBinary = Readable
|
|
56
|
+
/**
|
|
57
|
+
* Type alias that indicates that the Writable is not in objectMode,
|
|
58
|
+
* e.g reads a binary stream (like a gzip stream).
|
|
59
|
+
*/
|
|
60
|
+
export type WritableBinary = Writable
|
|
61
|
+
|
|
51
62
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
52
63
|
export interface TransformTyped<IN, OUT> extends Transform {}
|
|
53
64
|
|