UNPKG

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