Skip to content

Commit

Permalink
Refactor to aid optimization of non-try/catch code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 29, 2015
1 parent 9e147ee commit 9b2772a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
'use strict';

var strValue = String.prototype.valueOf;

module.exports = function isString(value) {
if (typeof value === 'string') { return true; }
if (typeof value !== 'object') { return false; }
var tryStringObject = function tryStringObject(value) {
try {
strValue.call(value);
return true;
} catch (e) {
return false;
}
};

module.exports = function isString(value) {
if (typeof value === 'string') { return true; }
if (typeof value !== 'object') { return false; }
return tryStringObject(value);
};

0 comments on commit 9b2772a

Please sign in to comment.