File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -26,25 +26,32 @@ export function parseNumber(
26
26
}
27
27
28
28
/**
29
- * Parses a case-insensitive string into a boolean.
29
+ * Parses a case-insensitive string into a boolean, or returns the original boolean .
30
30
* - Returns `false` for nullish input if `nullishBool` is true.
31
31
* - Returns `undefined` otherwise for nullish or unrecognized input.
32
32
*/
33
33
export function parseBoolean (
34
- str ?: string ,
34
+ input ?: string | boolean ,
35
35
nullishBool = false
36
36
) : boolean | undefined {
37
- if ( ! str ) {
37
+ // Handle nullish
38
+ if ( input == null || input === '' ) {
38
39
if ( ! isTestEnvironment ) {
39
40
console . warn ( 'parseBoolean: got nullish input' ) ;
40
41
}
41
42
return nullishBool ? false : undefined ;
42
43
}
43
44
44
- const lower = str . toLowerCase ( ) ;
45
+ // Handle actual boolean
46
+ if ( typeof input === 'boolean' ) {
47
+ return input ;
48
+ }
49
+
50
+ // Handle string case
51
+ const lower = input . toLowerCase ( ) ;
45
52
if ( lower === 'true' ) return true ;
46
53
if ( lower === 'false' ) return false ;
47
54
48
- console . warn ( `parseBoolean: expected 'true' or 'false', got "${ str } "` ) ;
55
+ console . warn ( `parseBoolean: expected 'true' or 'false', got "${ input } "` ) ;
49
56
return undefined ;
50
57
}
You can’t perform that action at this time.
0 commit comments