UNPKG

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