|
1 | 1 | import type { ParsingExtension } from '@app-config/core';
|
2 | 2 | import { AppConfigError } from '@app-config/core';
|
3 |
| -import { named, forKey, validateOptions, composeExtensions } from '@app-config/extension-utils'; |
| 3 | +import { named, forKey, composeExtensions } from '@app-config/extension-utils'; |
4 | 4 |
|
5 | 5 | /** Provides string parsing */
|
6 | 6 | export function parseDirective(): ParsingExtension {
|
@@ -28,36 +28,41 @@ export function parseDirective(): ParsingExtension {
|
28 | 28 | }
|
29 | 29 |
|
30 | 30 | if (typeof primitive === 'string') {
|
31 |
| - const parsed = Number.parseFloat(primitive); |
| 31 | + const floatValue = Number.parseFloat(primitive); |
32 | 32 |
|
33 |
| - if (Number.isNaN(parsed)) { |
| 33 | + if (Number.isNaN(floatValue)) { |
34 | 34 | throw new AppConfigError(`Failed to $parseFloat(${primitive})`);
|
35 | 35 | }
|
36 | 36 |
|
37 |
| - return parse(parsed, { shouldFlatten: true }); |
| 37 | + return parse(floatValue, { shouldFlatten: true }); |
38 | 38 | }
|
39 | 39 |
|
40 |
| - throw new AppConfigError(`Failed to $parseFloat(${parsed.toJSON()}) - invalid input type`); |
| 40 | + throw new AppConfigError( |
| 41 | + `Failed to $parseFloat(${parsed.toJSON() as string}) - invalid input type`, |
| 42 | + ); |
41 | 43 | }),
|
42 | 44 | forKey('$parseInt', (value) => async (parse) => {
|
43 | 45 | const parsed = await parse(value);
|
44 | 46 | const primitive = parsed.asPrimitive();
|
45 | 47 |
|
46 | 48 | if (typeof primitive === 'number') {
|
| 49 | + // eslint-disable-next-line no-bitwise |
47 | 50 | return parse(primitive | 0, { shouldFlatten: true });
|
48 | 51 | }
|
49 | 52 |
|
50 | 53 | if (typeof primitive === 'string') {
|
51 |
| - const parsed = Number.parseInt(primitive, 10); |
| 54 | + const intValue = Number.parseInt(primitive, 10); |
52 | 55 |
|
53 |
| - if (Number.isNaN(parsed)) { |
| 56 | + if (Number.isNaN(intValue)) { |
54 | 57 | throw new AppConfigError(`Failed to $parseInt(${primitive})`);
|
55 | 58 | }
|
56 | 59 |
|
57 |
| - return parse(parsed, { shouldFlatten: true }); |
| 60 | + return parse(intValue, { shouldFlatten: true }); |
58 | 61 | }
|
59 | 62 |
|
60 |
| - throw new AppConfigError(`Failed to $parseInt(${parsed.toJSON()}) - invalid input type`); |
| 63 | + throw new AppConfigError( |
| 64 | + `Failed to $parseInt(${parsed.toJSON() as string}) - invalid input type`, |
| 65 | + ); |
61 | 66 | }),
|
62 | 67 | ]),
|
63 | 68 | );
|
|
0 commit comments