Skip to content

Commit

Permalink
Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 28, 2015
1 parent 117676a commit 2d88bd6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index.js
@@ -0,0 +1,21 @@
'use strict';

var boolToStr = Boolean.prototype.toString;

var tryBooleanObject = function tryBooleanObject(value) {
try {
boolToStr.call(value);
return true;
} catch (e) {
return false;
}
};
var toStr = Object.prototype.toString;
var boolClass = '[object Boolean]';
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';

module.exports = function isBoolean(value) {
if (typeof value === 'boolean') { return true; }
if (typeof value !== 'object') { return false; }
return hasToStringTag ? tryBooleanObject(value) : toStr.call(value) === boolClass;
};

0 comments on commit 2d88bd6

Please sign in to comment.