Skip to content

Commit

Permalink
If @@toStringTag is not present, use the old-school Object#toString t…
Browse files Browse the repository at this point in the history
…est.
  • Loading branch information
ljharb committed Jan 30, 2015
1 parent 7c27f9f commit 30675ec
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -9,9 +9,12 @@ var tryStringObject = function tryStringObject(value) {
return false;
}
};
var toStr = Object.prototype.toString;
var strClass = '[object String]';
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';

module.exports = function isString(value) {
if (typeof value === 'string') { return true; }
if (typeof value !== 'object') { return false; }
return tryStringObject(value);
return hasToStringTag ? tryStringObject(value) : toStr.call(value) === strClass;
};

0 comments on commit 30675ec

Please sign in to comment.