blob: f44f7bbbabdba43b518bc9d4e38ebd5d9459b8e1 [file] [log] [blame]
Tim van der Lippefdbd42e2020-04-07 15:14:36 +01001'use strict';
2
3var strValue = String.prototype.valueOf;
4var tryStringObject = function tryStringObject(value) {
5 try {
6 strValue.call(value);
7 return true;
8 } catch (e) {
9 return false;
10 }
11};
12var toStr = Object.prototype.toString;
13var strClass = '[object String]';
Tim van der Lippebc3a0b72021-11-08 15:22:37 +000014var hasToStringTag = require('has-tostringtag/shams')();
Tim van der Lippefdbd42e2020-04-07 15:14:36 +010015
16module.exports = function isString(value) {
17 if (typeof value === 'string') {
18 return true;
19 }
20 if (typeof value !== 'object') {
21 return false;
22 }
23 return hasToStringTag ? tryStringObject(value) : toStr.call(value) === strClass;
24};