isBoolean.js 486 B

12345678910111213141516
  1. import assertString from './util/assertString';
  2. var defaultOptions = {
  3. loose: false
  4. };
  5. var strictBooleans = ['true', 'false', '1', '0'];
  6. var looseBooleans = [].concat(strictBooleans, ['yes', 'no']);
  7. export default function isBoolean(str) {
  8. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
  9. assertString(str);
  10. if (options.loose) {
  11. return looseBooleans.includes(str.toLowerCase());
  12. }
  13. return strictBooleans.includes(str);
  14. }