isBoolean.js 531 B

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