'use strict'; var fnToStr = Function.prototype.toString; var constructorRegex = /^\s*class\b/; var isES6ClassFn = function isES6ClassFunction(value) { try { var fnStr = fnToStr.call(value); return constructorRegex.test(fnStr); } catch (e) { return false; // not a function } }; var tryFunctionObject = function tryFunctionToStr(value) { try { if (isES6ClassFn(value)) { return false; } fnToStr.call(value); return true; } catch (e) { return false; } }; var toStr = Object.prototype.toString; var fnClass = '[object Function]'; var genClass = '[object GeneratorFunction]'; var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; module.exports = function isCallable(value) { if (!value) { return false; } if (typeof value !== 'function' && typeof value !== 'object') { return false; } if (typeof value === 'function' && !value.prototype) { return true; } if (hasToStringTag) { return tryFunctionObject(value); } if (isES6ClassFn(value)) { return false; } var strClass = toStr.call(value); return strClass === fnClass || strClass === genClass; };
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
.editorconfig | File | 286 B | 0644 |
|
.istanbul.yml | File | 993 B | 0644 |
|
.jscs.json | File | 4.03 KB | 0644 |
|
.travis.yml | File | 6.58 KB | 0644 |
|
CHANGELOG.md | File | 1.96 KB | 0644 |
|
LICENSE | File | 1.06 KB | 0644 |
|
Makefile | File | 3.74 KB | 0644 |
|
README.md | File | 1.93 KB | 0644 |
|
index.js | File | 1.09 KB | 0644 |
|
package.json | File | 2.85 KB | 0644 |
|
test.js | File | 5.41 KB | 0644 |
|