Tim van der Lippe | fdbd42e | 2020-04-07 15:14:36 +0100 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | var strValue = String.prototype.valueOf; |
| 4 | var tryStringObject = function tryStringObject(value) { |
| 5 | try { |
| 6 | strValue.call(value); |
| 7 | return true; |
| 8 | } catch (e) { |
| 9 | return false; |
| 10 | } |
| 11 | }; |
| 12 | var toStr = Object.prototype.toString; |
| 13 | var strClass = '[object String]'; |
Tim van der Lippe | 2c89197 | 2021-07-29 16:22:50 +0100 | [diff] [blame] | 14 | var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; |
Tim van der Lippe | fdbd42e | 2020-04-07 15:14:36 +0100 | [diff] [blame] | 15 | |
| 16 | module.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 | }; |