UNPKG

3.79 kBTypeScriptView Raw
1// disable automatic export
2export {};
3
4// Uses ArrayLike to admit Uint8 and co.
5type OutputBuffer = ArrayLike<number>;
6type InputBuffer = ArrayLike<number>;
7
8interface RandomOptions {
9 /** `Array` of 16 random bytes (0-255) */
10 random?: InputBuffer | undefined;
11}
12interface RngOptions {
13 /** Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) */
14 rng?: (() => InputBuffer) | undefined;
15}
16
17interface V1BaseOptions {
18 /** RFC "node" field as an `Array[6]` of byte values (per 4.1.6) */
19 node?: InputBuffer | undefined;
20 /** RFC "clock sequence" as a `Number` between 0 - 0x3fff */
21 clockseq?: number | undefined;
22 /** RFC "timestamp" field (`Number` of milliseconds, unix epoch) */
23 msecs?: number | Date | undefined;
24 /** RFC "timestamp" field (`Number` of nanoseconds to add to msecs, should be 0-10,000) */
25 nsecs?: number | undefined;
26}
27interface V1RandomOptions extends V1BaseOptions, RandomOptions {}
28interface V1RngOptions extends V1BaseOptions, RngOptions {}
29
30export type V1Options = V1RandomOptions | V1RngOptions;
31export type V4Options = RandomOptions | RngOptions;
32export type V6Options = V1Options;
33
34interface V7BaseOptions {
35 msecs?: number | Date | undefined;
36 seq?: number;
37}
38export type V7Options = (RandomOptions | RngOptions) & V7BaseOptions;
39
40type VToV = ((uuid: string) => string) & ((uuid: OutputBuffer) => Uint8Array);
41
42type v1String = (options?: V1Options) => string;
43type v1Buffer = <T extends OutputBuffer>(options: V1Options | null | undefined, buffer: T, offset?: number) => T;
44type v1 = v1Buffer & v1String;
45
46type v1ToV6 = VToV;
47
48type v4String = (options?: V4Options) => string;
49type v4Buffer = <T extends OutputBuffer>(options: V4Options | null | undefined, buffer: T, offset?: number) => T;
50type v4 = v4Buffer & v4String;
51
52type v3String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
53type v3Buffer = <T extends OutputBuffer>(
54 name: string | InputBuffer,
55 namespace: string | InputBuffer,
56 buffer: T,
57 offset?: number,
58) => T;
59interface v3Static {
60 // https://github.com/uuidjs/uuid/blob/master/src/v35.js#L16
61 DNS: string;
62 // https://github.com/uuidjs/uuid/blob/master/src/v35.js#L17
63 URL: string;
64}
65type v3 = v3Buffer & v3String & v3Static;
66
67type v5String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
68type v5Buffer = <T extends OutputBuffer>(
69 name: string | InputBuffer,
70 namespace: string | InputBuffer,
71 buffer: T,
72 offset?: number,
73) => T;
74interface v5Static {
75 // https://github.com/uuidjs/uuid/blob/master/src/v35.js#L16
76 DNS: string;
77 // https://github.com/uuidjs/uuid/blob/master/src/v35.js#L17
78 URL: string;
79}
80type v5 = v5Buffer & v5String & v5Static;
81
82type v6String = (options?: V6Options) => string;
83type v6Buffer = <T extends OutputBuffer>(options: V6Options | null | undefined, buffer: T, offset?: number) => T;
84type v6 = v6Buffer & v6String;
85
86type v6ToV1 = VToV;
87
88type v7String = (options?: V7Options) => string;
89type v7Buffer = <T extends OutputBuffer>(options: V7Options | null | undefined, buffer: T, offset?: number) => T;
90type v7 = v7Buffer & v7String;
91
92type NIL = string;
93type MAX = string;
94
95type parse = (uuid: string) => Uint8Array;
96type stringify = (buffer: InputBuffer, offset?: number) => string;
97type validate = (uuid: string) => boolean;
98type version = (uuid: string) => number;
99
100export const NIL: NIL;
101export const MAX: MAX;
102export const parse: parse;
103export const stringify: stringify;
104export const v1: v1;
105export const v1ToV6: v1ToV6;
106export const v3: v3;
107export const v4: v4;
108export const v5: v5;
109export const v6: v6;
110export const v6ToV1: v6ToV1;
111export const v7: v7;
112export const validate: validate;
113export const version: version;