@rjweb/utils
Advanced tools
Comparing version 1.12.0 to 1.12.1
@@ -131,6 +131,9 @@ "use strict"; | ||
}; | ||
const hash2 = pOptions.salt ? crypto.createHmac(pOptions.algorithm, pOptions.salt) : crypto.createHash(pOptions.algorithm); | ||
pOptions.algorithm = Array.isArray(pOptions.algorithm) ? pOptions.algorithm : [pOptions.algorithm]; | ||
const hashes = Object.fromEntries(pOptions.algorithm.map((a) => [a, pOptions.salt ? crypto.createHmac(a, pOptions.salt) : crypto.createHash(a)])); | ||
await new Promise((resolve, reject) => { | ||
stream2.on("data", (chunk) => { | ||
hash2.update(chunk); | ||
for (const hash2 of Object.values(hashes)) { | ||
hash2.update(chunk); | ||
} | ||
}); | ||
@@ -144,8 +147,7 @@ stream2.on("end", () => { | ||
}); | ||
let out; | ||
if (pOptions.output === "buffer") | ||
out = hash2.digest(); | ||
else | ||
out = hash2.digest(pOptions.output); | ||
return out; | ||
if (Array.isArray(options?.algorithm)) { | ||
return Object.fromEntries(pOptions.algorithm.map((a) => [a, pOptions.output === "buffer" ? hashes[a].digest() : hashes[a].digest(pOptions.output)])); | ||
} else { | ||
return pOptions.output === "buffer" ? hashes[pOptions.algorithm[0]].digest() : hashes[pOptions.algorithm[0]].digest(pOptions.output); | ||
} | ||
} | ||
@@ -152,0 +154,0 @@ // Annotate the CommonJS export names for ESM import in node: |
{ | ||
"name": "@rjweb/utils", | ||
"version": "1.12.0", | ||
"version": "1.12.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
@@ -116,9 +116,9 @@ "use strict"; | ||
}; | ||
const hash2 = pOptions.salt ? crypto.createHmac(pOptions.algorithm, pOptions.salt).update(input) : crypto.createHash(pOptions.algorithm).update(input); | ||
let out; | ||
if (pOptions.output === "buffer") | ||
out = hash2.digest(); | ||
else | ||
out = hash2.digest(pOptions.output); | ||
return out; | ||
pOptions.algorithm = Array.isArray(pOptions.algorithm) ? pOptions.algorithm : [pOptions.algorithm]; | ||
const hashes = Object.fromEntries(pOptions.algorithm.map((a) => [a, pOptions.salt ? crypto.createHmac(a, pOptions.salt).update(input) : crypto.createHash(a).update(input)])); | ||
if (Array.isArray(options?.algorithm)) { | ||
return Object.fromEntries(pOptions.algorithm.map((a) => [a, pOptions.output === "buffer" ? hashes[a].digest() : hashes[a].digest(pOptions.output)])); | ||
} else { | ||
return pOptions.output === "buffer" ? hashes[pOptions.algorithm[0]].digest() : hashes[pOptions.algorithm[0]].digest(pOptions.output); | ||
} | ||
} | ||
@@ -125,0 +125,0 @@ function encrypt(input, key, options) { |
@@ -95,6 +95,9 @@ import * as fs from "fs"; | ||
}; | ||
const hash2 = pOptions.salt ? crypto.createHmac(pOptions.algorithm, pOptions.salt) : crypto.createHash(pOptions.algorithm); | ||
pOptions.algorithm = Array.isArray(pOptions.algorithm) ? pOptions.algorithm : [pOptions.algorithm]; | ||
const hashes = Object.fromEntries(pOptions.algorithm.map((a) => [a, pOptions.salt ? crypto.createHmac(a, pOptions.salt) : crypto.createHash(a)])); | ||
await new Promise((resolve, reject) => { | ||
stream2.on("data", (chunk) => { | ||
hash2.update(chunk); | ||
for (const hash2 of Object.values(hashes)) { | ||
hash2.update(chunk); | ||
} | ||
}); | ||
@@ -108,8 +111,7 @@ stream2.on("end", () => { | ||
}); | ||
let out; | ||
if (pOptions.output === "buffer") | ||
out = hash2.digest(); | ||
else | ||
out = hash2.digest(pOptions.output); | ||
return out; | ||
if (Array.isArray(options?.algorithm)) { | ||
return Object.fromEntries(pOptions.algorithm.map((a) => [a, pOptions.output === "buffer" ? hashes[a].digest() : hashes[a].digest(pOptions.output)])); | ||
} else { | ||
return pOptions.output === "buffer" ? hashes[pOptions.algorithm[0]].digest() : hashes[pOptions.algorithm[0]].digest(pOptions.output); | ||
} | ||
} | ||
@@ -116,0 +118,0 @@ export { |
{ | ||
"name": "@rjweb/utils", | ||
"version": "1.12.0", | ||
"version": "1.12.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
@@ -75,9 +75,9 @@ import * as crypto from "crypto"; | ||
}; | ||
const hash2 = pOptions.salt ? crypto.createHmac(pOptions.algorithm, pOptions.salt).update(input) : crypto.createHash(pOptions.algorithm).update(input); | ||
let out; | ||
if (pOptions.output === "buffer") | ||
out = hash2.digest(); | ||
else | ||
out = hash2.digest(pOptions.output); | ||
return out; | ||
pOptions.algorithm = Array.isArray(pOptions.algorithm) ? pOptions.algorithm : [pOptions.algorithm]; | ||
const hashes = Object.fromEntries(pOptions.algorithm.map((a) => [a, pOptions.salt ? crypto.createHmac(a, pOptions.salt).update(input) : crypto.createHash(a).update(input)])); | ||
if (Array.isArray(options?.algorithm)) { | ||
return Object.fromEntries(pOptions.algorithm.map((a) => [a, pOptions.output === "buffer" ? hashes[a].digest() : hashes[a].digest(pOptions.output)])); | ||
} else { | ||
return pOptions.output === "buffer" ? hashes[pOptions.algorithm[0]].digest() : hashes[pOptions.algorithm[0]].digest(pOptions.output); | ||
} | ||
} | ||
@@ -84,0 +84,0 @@ function encrypt(input, key, options) { |
@@ -6,2 +6,3 @@ /// <reference types="node" /> | ||
import * as crypto from "crypto"; | ||
import { ArrayOrNot } from "."; | ||
/** | ||
@@ -86,3 +87,3 @@ * Get Files from a folder | ||
* @since 1.12.0 | ||
*/ export declare function hash<Options extends { | ||
*/ export declare function hash<const Options extends { | ||
/** | ||
@@ -92,3 +93,3 @@ * The Algorithm to use | ||
* @since 1.12.0 | ||
*/ algorithm?: string; | ||
*/ algorithm?: ArrayOrNot<string>; | ||
/** | ||
@@ -103,2 +104,4 @@ * The Salt to add | ||
*/ output?: crypto.BinaryToTextEncoding | 'buffer'; | ||
}>(file: fs.PathLike, options?: Options): Promise<Options['output'] extends 'buffer' ? Buffer : string>; | ||
}>(file: fs.PathLike, options?: Options): Promise<Options['algorithm'] extends Array<any> ? { | ||
[Key in Options['algorithm'][number]]: Options['output'] extends 'buffer' ? Buffer : string; | ||
} : Options['output'] extends 'buffer' ? Buffer : string>; |
@@ -16,2 +16,3 @@ /// <reference types="node" /> | ||
export declare const Version: string; | ||
export type ArrayOrNot<Type> = Type | Type[]; | ||
export type DeepRequired<Type> = Type extends {} ? Type extends Map<any, any> ? Required<Type> : Type extends Set<any> ? Required<Type> : Type extends Buffer ? Required<Type> : Type extends Function ? Required<Type> : Type extends Array<any> ? Required<Type> : Type extends {} ? { | ||
@@ -18,0 +19,0 @@ [Key in keyof Type]-?: DeepRequired<Type[Key]>; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import * as crypto from "crypto"; | ||
import { ArrayOrNot } from "src"; | ||
/** | ||
@@ -18,3 +19,3 @@ * Hash a String | ||
* @since 1.0.0 | ||
*/ algorithm?: string; | ||
*/ algorithm?: ArrayOrNot<string>; | ||
/** | ||
@@ -29,3 +30,5 @@ * The Salt to add | ||
*/ output?: crypto.BinaryToTextEncoding | 'buffer'; | ||
}>(input: string, options?: Options): Options['output'] extends 'buffer' ? Buffer : string; | ||
}>(input: string, options?: Options): Options['algorithm'] extends Array<any> ? { | ||
[Key in Options['algorithm'][number]]: Options['output'] extends 'buffer' ? Buffer : string; | ||
} : Options['output'] extends 'buffer' ? Buffer : string; | ||
/** | ||
@@ -32,0 +35,0 @@ * Encrypt a String |
{ | ||
"name": "@rjweb/utils", | ||
"version": "1.12.0", | ||
"version": "1.12.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1840662
6636