UNPKG

2.94 kBTypeScriptView Raw
1// Type definitions for uuid 8.3
2// Project: https://github.com/uuidjs/uuid
3// Definitions by: Oliver Hoffmann <https://github.com/iamolivinius>
4// Felipe Ochoa <https://github.com/felipeochoa>
5// Chris Barth <https://github.com/cjbarth>
6// Linus Unnebäck <https://github.com/LinusU>
7// Christoph Tavan <https://github.com/ctavan>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9// TypeScript Version: 2.8
10
11// disable automatic export
12export {};
13
14// Uses ArrayLike to admit Unit8 and co.
15type OutputBuffer = ArrayLike<number>;
16type InputBuffer = ArrayLike<number>;
17
18interface RandomOptions {
19 random?: InputBuffer | undefined;
20}
21interface RngOptions {
22 rng?: (() => InputBuffer) | undefined;
23}
24
25interface V1BaseOptions {
26 node?: InputBuffer | undefined;
27 clockseq?: number | undefined;
28 msecs?: number | Date | undefined;
29 nsecs?: number | undefined;
30}
31interface V1RandomOptions extends V1BaseOptions, RandomOptions {}
32interface V1RngOptions extends V1BaseOptions, RngOptions {}
33
34export type V1Options = V1RandomOptions | V1RngOptions;
35export type V4Options = RandomOptions | RngOptions;
36
37type v1String = (options?: V1Options) => string;
38type v1Buffer = <T extends OutputBuffer>(options: V1Options | null | undefined, buffer: T, offset?: number) => T;
39type v1 = v1Buffer & v1String;
40
41type v4String = (options?: V4Options) => string;
42type v4Buffer = <T extends OutputBuffer>(options: V4Options | null | undefined, buffer: T, offset?: number) => T;
43type v4 = v4Buffer & v4String;
44
45type v3String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
46type v3Buffer = <T extends OutputBuffer>(name: string | InputBuffer, namespace: string | InputBuffer, buffer: T, offset?: number) => T;
47interface v3Static {
48 // https://github.com/uuidjs/uuid/blob/master/src/v35.js#L22
49 DNS: string;
50 // https://github.com/uuidjs/uuid/blob/master/src/v35.js#L23
51 URL: string;
52}
53type v3 = v3Buffer & v3String & v3Static;
54
55type v5String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
56type v5Buffer = <T extends OutputBuffer>(name: string | InputBuffer, namespace: string | InputBuffer, buffer: T, offset?: number) => T;
57interface v5Static {
58 // https://github.com/uuidjs/uuid/blob/master/src/v35.js#L22
59 DNS: string;
60 // https://github.com/uuidjs/uuid/blob/master/src/v35.js#L23
61 URL: string;
62}
63type v5 = v5Buffer & v5String & v5Static;
64
65type NIL = string;
66
67type parse = (uuid: string) => OutputBuffer;
68type stringify = (buffer: InputBuffer, offset?: number) => string;
69type validate = (uuid: string) => boolean;
70type version = (uuid: string) => number;
71
72export const NIL: NIL;
73export const parse: parse;
74export const stringify: stringify;
75export const v1: v1;
76export const v3: v3;
77export const v4: v4;
78export const v5: v5;
79export const validate: validate;
80export const version: version;