-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.d.ts
47 lines (37 loc) · 1.45 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {type Encoding as CryptoEncoding} from 'node:crypto';
import {type LiteralUnion} from 'type-fest';
export type Encoding = CryptoEncoding | 'buffer';
export type Algorithm = LiteralUnion<'md5' | 'sha1' | 'sha256' | 'sha512', string>;
export type Options = {
/**
The encoding of the returned hash.
@default 'hex'
*/
readonly encoding?: Encoding;
/**
_Don't use `'md5'` or `'sha1'` for anything sensitive. [They're insecure.](http://googleonlinesecurity.blogspot.no/2014/09/gradually-sunsetting-sha-1.html)_
@default 'sha512'
*/
readonly algorithm?: Algorithm;
};
export type BufferOptions = {
readonly encoding: 'buffer';
} & Options;
/**
Get the hash of an object.
The output is deterministic for repeated runs on the same Node.js / browser version. It should also be fairly deterministic across JavaScript engines. However, because the stability of grapheme clusters across Unicode versions is not guaranteed, determinism cannot be guaranteed across JavaScript engines and versions. There are also other factors that can make it nondeterministic, like values with floating point numbers and dates.
@example
```
import hashObject from 'hash-object';
hashObject({'🦄': '🌈'}, {algorithm: 'sha1'});
//=> '3de3bc784035b559784fc276f47493d60555fba3'
```
*/
export default function hashObject(
object: Record<string, any>,
options: BufferOptions
): Uint8Array;
export default function hashObject(
object: Record<string, any>,
options?: Options
): string;