isString.js 889 B

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