Sha256: 6ad8035fb10fca21592cc49ea99b2db958beb6b95855f738324a04cecb5877c1

Contents?: true

Size: 1.09 KB

Versions: 65

Compression:

Stored size: 1.09 KB

Contents

'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;
};

Version data entries

65 entries across 65 versions & 8 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/is-callable/index.js
disco_app-0.18.2 test/dummy/node_modules/is-callable/index.js
disco_app-0.16.1 test/dummy/node_modules/is-callable/index.js
disco_app-0.15.2 test/dummy/node_modules/is-callable/index.js
disco_app-0.18.4 test/dummy/node_modules/is-callable/index.js
disco_app-0.18.1 test/dummy/node_modules/is-callable/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/is-callable/index.js
disco_app-0.14.0 test/dummy/node_modules/is-callable/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/is-callable/index.js
enju_library-0.3.8 spec/dummy/node_modules/is-callable/index.js
ilog-0.4.1 node_modules/is-callable/index.js
ilog-0.4.0 node_modules/is-callable/index.js
ilog-0.3.3 node_modules/is-callable/index.js
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/is-callable/index.js
jester-data-8.0.0 node_modules/is-callable/index.js
ezii-os-5.2.1 node_modules/is-callable/index.js
ezii-os-2.0.1 node_modules/is-callable/index.js
ezii-os-1.1.0 node_modules/is-callable/index.js
ezii-os-1.0.0 node_modules/is-callable/index.js
ezii-os-0.0.0.1.0 node_modules/is-callable/index.js