index.js 715 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var callBound = require('call-bind/callBound');
  3. var $boolToStr = callBound('Boolean.prototype.toString');
  4. var $toString = callBound('Object.prototype.toString');
  5. var tryBooleanObject = function booleanBrandCheck(value) {
  6. try {
  7. $boolToStr(value);
  8. return true;
  9. } catch (e) {
  10. return false;
  11. }
  12. };
  13. var boolClass = '[object Boolean]';
  14. var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag;
  15. module.exports = function isBoolean(value) {
  16. if (typeof value === 'boolean') {
  17. return true;
  18. }
  19. if (value === null || typeof value !== 'object') {
  20. return false;
  21. }
  22. return hasToStringTag && Symbol.toStringTag in value ? tryBooleanObject(value) : $toString(value) === boolClass;
  23. };