UNPKG

3.21 kBTypeScriptView Raw
1// Type definitions for object-hash 2.2
2// Project: https://github.com/puleos/object-hash
3// Definitions by: Michael Zabka <https://github.com/misak113>
4// Artur Diniz <https://github.com/artdiniz>
5// Martin Badin <https://github.com/martin-badin>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
8declare namespace objectHash {
9 /**
10 * @see https://github.com/puleos/object-hash#hashsha1value
11 */
12 function sha1(object: {} | null): string;
13 /**
14 * @see https://github.com/puleos/object-hash#hashkeysvalue
15 */
16 function keys(object: {} | null): string;
17 /**
18 * @see https://github.com/puleos/object-hash#hashmd5value
19 */
20 function MD5(object: {} | null): string;
21 /**
22 * @see https://github.com/puleos/object-hash#hashkeysmd5value
23 */
24 function keysMD5(object: {} | null): string;
25 /**
26 * @see https://github.com/puleos/object-hash#hashwritetostreamvalue-options-stream
27 */
28 function writeToStream(value: any, stream: Stream): void;
29 function writeToStream(value: any, options: Options, stream: Stream): void;
30
31 type BufferEncoding =
32 | 'ascii'
33 | 'base64'
34 | 'binary'
35 | 'hex'
36 | 'latin1'
37 | 'ucs-2'
38 | 'ucs2'
39 | 'utf-8'
40 | 'utf16le'
41 | 'utf8';
42
43 interface Stream {
44 update?(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
45 write?(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
46 }
47
48 interface BaseOptions {
49 /**
50 * @default 'sha1'
51 */
52 algorithm?: 'sha1' | 'md5' | 'passthrough' | undefined;
53
54 excludeKeys?: ((key: string) => boolean) | undefined;
55 /**
56 * @default false
57 */
58 excludeValues?: boolean | undefined;
59 /**
60 * @default false
61 */
62 ignoreUnknown?: boolean | undefined;
63
64 replacer?: ((value: any) => any) | undefined;
65 /**
66 * @default true
67 */
68 respectFunctionNames?: boolean | undefined;
69 /**
70 * @default true
71 */
72 respectFunctionProperties?: boolean | undefined;
73 /**
74 * @default true
75 */
76 respectType?: boolean | undefined;
77 /**
78 * @default false
79 */
80 unorderedArrays?: boolean | undefined;
81 /**
82 * @default true
83 */
84 unorderedObjects?: boolean | undefined;
85 /**
86 * @default true
87 */
88 unorderedSets?: boolean | undefined;
89 }
90
91 interface NormalOption extends BaseOptions {
92 /**
93 * @default 'hex'
94 */
95 encoding?: 'hex' | 'binary' | 'base64' | undefined;
96 }
97
98 interface WithBufferOption extends BaseOptions {
99 encoding: 'buffer';
100 }
101
102 type Options = NormalOption | WithBufferOption;
103}
104
105/**
106 * @see https://github.com/puleos/object-hash#hashvalue-options
107 */
108declare function objectHash(object: {} | null, options?: objectHash.NormalOption): string;
109declare function objectHash(object: {} | null, options?: objectHash.WithBufferOption): Buffer;
110
111export = objectHash;
112
\No newline at end of file