UNPKG

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