isString.js 723 B

12345678910111213141516171819202122232425262728293031
  1. var baseGetTag = require('./_baseGetTag'),
  2. isArray = require('./isArray'),
  3. isObjectLike = require('./isObjectLike');
  4. /** `Object#toString` result references. */
  5. var stringTag = '[object String]';
  6. /**
  7. * Checks if `value` is classified as a `String` primitive or object.
  8. *
  9. * @static
  10. * @since 0.1.0
  11. * @memberOf _
  12. * @category Lang
  13. * @param {*} value The value to check.
  14. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  15. * @example
  16. *
  17. * _.isString('abc');
  18. * // => true
  19. *
  20. * _.isString(1);
  21. * // => false
  22. */
  23. function isString(value) {
  24. return typeof value == 'string' ||
  25. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  26. }
  27. module.exports = isString;