index.js 578 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var strValue = String.prototype.valueOf;
  3. var tryStringObject = function tryStringObject(value) {
  4. try {
  5. strValue.call(value);
  6. return true;
  7. } catch (e) {
  8. return false;
  9. }
  10. };
  11. var toStr = Object.prototype.toString;
  12. var strClass = '[object String]';
  13. var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag;
  14. module.exports = function isString(value) {
  15. if (typeof value === 'string') {
  16. return true;
  17. }
  18. if (typeof value !== 'object') {
  19. return false;
  20. }
  21. return hasToStringTag ? tryStringObject(value) : toStr.call(value) === strClass;
  22. };