isBoolean.js 926 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var isObjectLike = require('./isObjectLike');
  2. /** `Object#toString` result references. */
  3. var boolTag = '[object Boolean]';
  4. /** Used for built-in method references. */
  5. var objectProto = Object.prototype;
  6. /**
  7. * Used to resolve the
  8. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  9. * of values.
  10. */
  11. var objectToString = objectProto.toString;
  12. /**
  13. * Checks if `value` is classified as a boolean primitive or object.
  14. *
  15. * @static
  16. * @memberOf _
  17. * @since 0.1.0
  18. * @category Lang
  19. * @param {*} value The value to check.
  20. * @returns {boolean} Returns `true` if `value` is correctly classified,
  21. * else `false`.
  22. * @example
  23. *
  24. * _.isBoolean(false);
  25. * // => true
  26. *
  27. * _.isBoolean(null);
  28. * // => false
  29. */
  30. function isBoolean(value) {
  31. return value === true || value === false ||
  32. (isObjectLike(value) && objectToString.call(value) == boolTag);
  33. }
  34. module.exports = isBoolean;