UNPKG

4.08 kBTypeScriptView Raw
1declare namespace WebIDLConversions {
2 interface Globals {
3 [key: string]: unknown;
4
5 Number: (value?: unknown) => number;
6 String: (value?: unknown) => string;
7 TypeError: new(message?: string) => TypeError;
8 }
9
10 interface Options {
11 context?: string | undefined;
12 globals?: Globals | undefined;
13 }
14
15 interface IntegerOptions extends Options {
16 enforceRange?: boolean | undefined;
17 clamp?: boolean | undefined;
18 }
19
20 interface StringOptions extends Options {
21 treatNullAsEmptyString?: boolean | undefined;
22 }
23
24 interface BufferSourceOptions extends Options {
25 allowShared?: boolean | undefined;
26 }
27
28 type IntegerConversion = (V: unknown, opts?: IntegerOptions) => number;
29 type StringConversion = (V: unknown, opts?: StringOptions) => string;
30 type NumberConversion = (V: unknown, opts?: Options) => number;
31}
32
33declare const WebIDLConversions: {
34 any<V>(V: V, opts?: WebIDLConversions.Options): V;
35 undefined(V?: unknown, opts?: WebIDLConversions.Options): void;
36 boolean(V: unknown, opts?: WebIDLConversions.Options): boolean;
37
38 byte(V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
39 octet(V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
40
41 short(V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
42 ["unsigned short"](V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
43
44 long(V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
45 ["unsigned long"](V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
46
47 ["long long"](V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
48 ["unsigned long long"](V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
49
50 double(V: unknown, opts?: WebIDLConversions.Options): number;
51 ["unrestricted double"](V: unknown, opts?: WebIDLConversions.Options): number;
52
53 float(V: unknown, opts?: WebIDLConversions.Options): number;
54 ["unrestricted float"](V: unknown, opts?: WebIDLConversions.Options): number;
55
56 DOMString(V: unknown, opts?: WebIDLConversions.StringOptions): string;
57 ByteString(V: unknown, opts?: WebIDLConversions.StringOptions): string;
58 USVString(V: unknown, opts?: WebIDLConversions.StringOptions): string;
59
60 object<V>(V: V, opts?: WebIDLConversions.Options): V extends object ? V : V & object;
61 ArrayBuffer(
62 V: unknown,
63 opts?: WebIDLConversions.BufferSourceOptions & { allowShared?: false | undefined },
64 ): ArrayBuffer;
65 ArrayBuffer(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): ArrayBufferLike;
66 DataView(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): DataView;
67
68 Int8Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Int8Array;
69 Int16Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Int16Array;
70 Int32Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Int32Array;
71
72 Uint8Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Uint8Array;
73 Uint16Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Uint16Array;
74 Uint32Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Uint32Array;
75 Uint8ClampedArray(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Uint8ClampedArray;
76
77 Float32Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Float32Array;
78 Float64Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Float64Array;
79
80 ArrayBufferView(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): ArrayBufferView;
81 BufferSource(
82 V: unknown,
83 opts?: WebIDLConversions.BufferSourceOptions & { allowShared?: false | undefined },
84 ): ArrayBuffer | ArrayBufferView;
85 BufferSource(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): ArrayBufferLike | ArrayBufferView;
86
87 DOMTimeStamp(V: unknown, opts?: WebIDLConversions.Options): number;
88};
89
90// This can't use ES6 style exports, as those can't have spaces in export names.
91export = WebIDLConversions;