-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add loose option to isBoolean validator
- Loading branch information
Bryan Brophy
committed
May 25, 2021
1 parent
907bb07
commit ba00c97
Showing
3 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
import assertString from './util/assertString'; | ||
|
||
export default function isBoolean(str) { | ||
const defaultOptions = { loose: false }; | ||
|
||
export default function isBoolean(str, options = defaultOptions) { | ||
assertString(str); | ||
return (['true', 'false', '1', '0'].indexOf(str) >= 0); | ||
|
||
const strictBooleans = ['true', 'false', '1', '0']; | ||
const looseBooleans = [...strictBooleans, 'yes', 'no']; | ||
|
||
if (options.loose) { | ||
return (looseBooleans.indexOf(str.toLowerCase()) >= 0); | ||
} | ||
|
||
return (strictBooleans.indexOf(str) >= 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters