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(
2626}
2727
2828/**
29- * Parses a case-insensitive string into a boolean.
29+ * Parses a case-insensitive string into a boolean, or returns the original boolean .
3030 * - Returns `false` for nullish input if `nullishBool` is true.
3131 * - Returns `undefined` otherwise for nullish or unrecognized input.
3232 */
3333export function parseBoolean (
34- str ?: string ,
34+ input ?: string | boolean ,
3535 nullishBool = false
3636) : boolean | undefined {
37- if ( ! str ) {
37+ // Handle nullish
38+ if ( input == null || input === '' ) {
3839 if ( ! isTestEnvironment ) {
3940 console . warn ( 'parseBoolean: got nullish input' ) ;
4041 }
4142 return nullishBool ? false : undefined ;
4243 }
4344
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 ( ) ;
4552 if ( lower === 'true' ) return true ;
4653 if ( lower === 'false' ) return false ;
4754
48- console . warn ( `parseBoolean: expected 'true' or 'false', got "${ str } "` ) ;
55+ console . warn ( `parseBoolean: expected 'true' or 'false', got "${ input } "` ) ;
4956 return undefined ;
5057}
You can’t perform that action at this time.
0 commit comments