UNPKG

923 BJavaScriptView Raw
1import isObjectLike from './isObjectLike';
2
3/** `Object#toString` result references. */
4var symbolTag = '[object Symbol]';
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 `Symbol` primitive or object.
18 *
19 * @static
20 * @memberOf _
21 * @since 4.0.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 * _.isSymbol(Symbol.iterator);
29 * // => true
30 *
31 * _.isSymbol('abc');
32 * // => false
33 */
34function isSymbol(value) {
35 return typeof value == 'symbol' ||
36 (isObjectLike(value) && objectToString.call(value) == symbolTag);
37}
38
39export default isSymbol;