isSymbol.js 928 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var isObjectLike = require('./isObjectLike');
  2. /** `Object#toString` result references. */
  3. var symbolTag = '[object Symbol]';
  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 `Symbol` primitive or object.
  14. *
  15. * @static
  16. * @memberOf _
  17. * @since 4.0.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. * _.isSymbol(Symbol.iterator);
  25. * // => true
  26. *
  27. * _.isSymbol('abc');
  28. * // => false
  29. */
  30. function isSymbol(value) {
  31. return typeof value == 'symbol' ||
  32. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  33. }
  34. module.exports = isSymbol;