1 | /**
|
2 | * Give an input string, strictly parses a boolean value.
|
3 | *
|
4 | * @param value The boolean string to parse.
|
5 | * @returns true for "true", false for "false", otherwise an error is thrown.
|
6 | */
|
7 | export declare const parseBoolean: (value: string) => boolean;
|
8 | export declare const expectBoolean: (value: any) => boolean | undefined;
|
9 | /**
|
10 | * Asserts a value is a number and returns it.
|
11 | *
|
12 | * @param value A value that is expected to be a number.
|
13 | * @returns The value if it's a number, undefined if it's null/undefined,
|
14 | * otherwise an error is thrown.
|
15 | */
|
16 | export declare const expectNumber: (value: any) => number | undefined;
|
17 | /**
|
18 | * Asserts a value is a 32-bit float and returns it.
|
19 | *
|
20 | * @param value A value that is expected to be a 32-bit float.
|
21 | * @returns The value if it's a float, undefined if it's null/undefined,
|
22 | * otherwise an error is thrown.
|
23 | */
|
24 | export declare const expectFloat32: (value: any) => number | undefined;
|
25 | /**
|
26 | * Asserts a value is an integer and returns it.
|
27 | *
|
28 | * @param value A value that is expected to be an integer.
|
29 | * @returns The value if it's an integer, undefined if it's null/undefined,
|
30 | * otherwise an error is thrown.
|
31 | */
|
32 | export declare const expectLong: (value: any) => number | undefined;
|
33 | /**
|
34 | * @deprecated Use expectLong
|
35 | */
|
36 | export declare const expectInt: (value: any) => number | undefined;
|
37 | /**
|
38 | * Asserts a value is a 32-bit integer and returns it.
|
39 | *
|
40 | * @param value A value that is expected to be an integer.
|
41 | * @returns The value if it's an integer, undefined if it's null/undefined,
|
42 | * otherwise an error is thrown.
|
43 | */
|
44 | export declare const expectInt32: (value: any) => number | undefined;
|
45 | /**
|
46 | * Asserts a value is a 16-bit integer and returns it.
|
47 | *
|
48 | * @param value A value that is expected to be an integer.
|
49 | * @returns The value if it's an integer, undefined if it's null/undefined,
|
50 | * otherwise an error is thrown.
|
51 | */
|
52 | export declare const expectShort: (value: any) => number | undefined;
|
53 | /**
|
54 | * Asserts a value is an 8-bit integer and returns it.
|
55 | *
|
56 | * @param value A value that is expected to be an integer.
|
57 | * @returns The value if it's an integer, undefined if it's null/undefined,
|
58 | * otherwise an error is thrown.
|
59 | */
|
60 | export declare const expectByte: (value: any) => number | undefined;
|
61 | /**
|
62 | * Asserts a value is not null or undefined and returns it, or throws an error.
|
63 | *
|
64 | * @param value A value that is expected to be defined
|
65 | * @param location The location where we're expecting to find a defined object (optional)
|
66 | * @returns The value if it's not undefined, otherwise throws an error
|
67 | */
|
68 | export declare const expectNonNull: <T>(value: T | null | undefined, location?: string | undefined) => T;
|
69 | /**
|
70 | * Asserts a value is an JSON-like object and returns it. This is expected to be used
|
71 | * with values parsed from JSON (arrays, objects, numbers, strings, booleans).
|
72 | *
|
73 | * @param value A value that is expected to be an object
|
74 | * @returns The value if it's an object, undefined if it's null/undefined,
|
75 | * otherwise an error is thrown.
|
76 | */
|
77 | export declare const expectObject: (value: any) => {
|
78 | [key: string]: any;
|
79 | } | undefined;
|
80 | /**
|
81 | * Asserts a value is a string and returns it.
|
82 | *
|
83 | * @param value A value that is expected to be a string.
|
84 | * @returns The value if it's a string, undefined if it's null/undefined,
|
85 | * otherwise an error is thrown.
|
86 | */
|
87 | export declare const expectString: (value: any) => string | undefined;
|
88 | /**
|
89 | * Asserts a value is a JSON-like object with only one non-null/non-undefined key and
|
90 | * returns it.
|
91 | *
|
92 | * @param value A value that is expected to be an object with exactly one non-null,
|
93 | * non-undefined key.
|
94 | * @return the value if it's a union, undefined if it's null/undefined, otherwise
|
95 | * an error is thrown.
|
96 | */
|
97 | export declare const expectUnion: (value: unknown) => {
|
98 | [key: string]: any;
|
99 | } | undefined;
|
100 | /**
|
101 | * Parses a value into a double. If the value is null or undefined, undefined
|
102 | * will be returned. If the value is a string, it will be parsed by the standard
|
103 | * parseFloat with one exception: NaN may only be explicitly set as the string
|
104 | * "NaN", any implicit Nan values will result in an error being thrown. If any
|
105 | * other type is provided, an exception will be thrown.
|
106 | *
|
107 | * @param value A number or string representation of a double.
|
108 | * @returns The value as a number, or undefined if it's null/undefined.
|
109 | */
|
110 | export declare const strictParseDouble: (value: string | number) => number | undefined;
|
111 | /**
|
112 | * @deprecated Use strictParseDouble
|
113 | */
|
114 | export declare const strictParseFloat: (value: string | number) => number | undefined;
|
115 | /**
|
116 | * Parses a value into a float. If the value is null or undefined, undefined
|
117 | * will be returned. If the value is a string, it will be parsed by the standard
|
118 | * parseFloat with one exception: NaN may only be explicitly set as the string
|
119 | * "NaN", any implicit Nan values will result in an error being thrown. If any
|
120 | * other type is provided, an exception will be thrown.
|
121 | *
|
122 | * @param value A number or string representation of a float.
|
123 | * @returns The value as a number, or undefined if it's null/undefined.
|
124 | */
|
125 | export declare const strictParseFloat32: (value: string | number) => number | undefined;
|
126 | /**
|
127 | * Asserts a value is a number and returns it. If the value is a string
|
128 | * representation of a non-numeric number type (NaN, Infinity, -Infinity),
|
129 | * the value will be parsed. Any other string value will result in an exception
|
130 | * being thrown. Null or undefined will be returned as undefined. Any other
|
131 | * type will result in an exception being thrown.
|
132 | *
|
133 | * @param value A number or string representation of a non-numeric float.
|
134 | * @returns The value as a number, or undefined if it's null/undefined.
|
135 | */
|
136 | export declare const limitedParseDouble: (value: string | number) => number | undefined;
|
137 | /**
|
138 | * @deprecated Use limitedParseDouble
|
139 | */
|
140 | export declare const handleFloat: (value: string | number) => number | undefined;
|
141 | /**
|
142 | * @deprecated Use limitedParseDouble
|
143 | */
|
144 | export declare const limitedParseFloat: (value: string | number) => number | undefined;
|
145 | /**
|
146 | * Asserts a value is a 32-bit float and returns it. If the value is a string
|
147 | * representation of a non-numeric number type (NaN, Infinity, -Infinity),
|
148 | * the value will be parsed. Any other string value will result in an exception
|
149 | * being thrown. Null or undefined will be returned as undefined. Any other
|
150 | * type will result in an exception being thrown.
|
151 | *
|
152 | * @param value A number or string representation of a non-numeric float.
|
153 | * @returns The value as a number, or undefined if it's null/undefined.
|
154 | */
|
155 | export declare const limitedParseFloat32: (value: string | number) => number | undefined;
|
156 | /**
|
157 | * Parses a value into an integer. If the value is null or undefined, undefined
|
158 | * will be returned. If the value is a string, it will be parsed by parseFloat
|
159 | * and the result will be asserted to be an integer. If the parsed value is not
|
160 | * an integer, or the raw value is any type other than a string or number, an
|
161 | * exception will be thrown.
|
162 | *
|
163 | * @param value A number or string representation of an integer.
|
164 | * @returns The value as a number, or undefined if it's null/undefined.
|
165 | */
|
166 | export declare const strictParseLong: (value: string | number) => number | undefined;
|
167 | /**
|
168 | * @deprecated Use strictParseLong
|
169 | */
|
170 | export declare const strictParseInt: (value: string | number) => number | undefined;
|
171 | /**
|
172 | * Parses a value into a 32-bit integer. If the value is null or undefined, undefined
|
173 | * will be returned. If the value is a string, it will be parsed by parseFloat
|
174 | * and the result will be asserted to be an integer. If the parsed value is not
|
175 | * an integer, or the raw value is any type other than a string or number, an
|
176 | * exception will be thrown.
|
177 | *
|
178 | * @param value A number or string representation of a 32-bit integer.
|
179 | * @returns The value as a number, or undefined if it's null/undefined.
|
180 | */
|
181 | export declare const strictParseInt32: (value: string | number) => number | undefined;
|
182 | /**
|
183 | * Parses a value into a 16-bit integer. If the value is null or undefined, undefined
|
184 | * will be returned. If the value is a string, it will be parsed by parseFloat
|
185 | * and the result will be asserted to be an integer. If the parsed value is not
|
186 | * an integer, or the raw value is any type other than a string or number, an
|
187 | * exception will be thrown.
|
188 | *
|
189 | * @param value A number or string representation of a 16-bit integer.
|
190 | * @returns The value as a number, or undefined if it's null/undefined.
|
191 | */
|
192 | export declare const strictParseShort: (value: string | number) => number | undefined;
|
193 | /**
|
194 | * Parses a value into an 8-bit integer. If the value is null or undefined, undefined
|
195 | * will be returned. If the value is a string, it will be parsed by parseFloat
|
196 | * and the result will be asserted to be an integer. If the parsed value is not
|
197 | * an integer, or the raw value is any type other than a string or number, an
|
198 | * exception will be thrown.
|
199 | *
|
200 | * @param value A number or string representation of an 8-bit integer.
|
201 | * @returns The value as a number, or undefined if it's null/undefined.
|
202 | */
|
203 | export declare const strictParseByte: (value: string | number) => number | undefined;
|