UNPKG

2.32 kBTypeScriptView Raw
1// Type definitions for imurmurhash 0.1
2// Project: https://github.com/jensyt/imurmurhash-js
3// Definitions by: Jiayu Liu <https://github.com/Jimexist>
4// Piotr Błażejewicz <https://github.com/peterblazejewicz>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7/**
8 * An incremental implementation of MurmurHash3 for JavaScript
9 */
10interface MurmurHash3 {
11 /**
12 * Get the result of the hash as a 32-bit positive integer.
13 * This performs the tail and finalizer portions of the algorithm, but does not store the result in the state object.
14 * This means that it is perfectly safe to get results and then continue adding strings via hash.
15 */
16 result(): number;
17
18 /**
19 * Reset the state object for reuse, optionally using the given seed (defaults to 0 like the constructor). Returns this so calls can be chained.
20 * @default 0
21 */
22 reset(seed?: number): this;
23
24 /**
25 * Incrementally add string to the hash.
26 * This can be called as many times as you want for the hash state object, including after a call to result()
27 */
28 hash(value: string): this;
29}
30declare var MurmurHash3: {
31 /**
32 * Get a hash state object, optionally initialized with the given string and seed.
33 * Seed must be a positive integer if provided.
34 * Calling this function without the new keyword will return a cached state object that has been reset.
35 * This is safe to use as long as the object is only used from a single thread and no other hashes are created while operating on this one.
36 * If this constraint cannot be met, you can use new to create a new state object
37 */
38 (text?: string, seed?: number): MurmurHash3;
39 /**
40 * Get a hash state object, optionally initialized with the given string and seed.
41 * Seed must be a positive integer if provided.
42 * Calling this function without the new keyword will return a cached state object that has been reset.
43 * This is safe to use as long as the object is only used from a single thread and no other hashes are created while operating on this one.
44 * If this constraint cannot be met, you can use new to create a new state object
45 */
46 new (text?: string, seed?: number): MurmurHash3;
47};
48
49export as namespace MurmurHash3;
50export = MurmurHash3;