is-callable
Advanced tools
Comparing version 1.0.4 to 1.1.0
{ | ||
"es3": true, | ||
"additionalRules": [], | ||
"requireSemicolons": true, | ||
"disallowMultipleSpaces": true, | ||
"disallowIdentifierNames": [], | ||
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"], | ||
@@ -10,2 +18,16 @@ | ||
"disallowSpaceBeforeComma": true, | ||
"disallowSpaceBeforeSemicolon": true, | ||
"disallowNodeTypes": [ | ||
"DebuggerStatement", | ||
"ForInStatement", | ||
"LabeledStatement", | ||
"SwitchCase", | ||
"SwitchStatement", | ||
"WithStatement" | ||
], | ||
"requireObjectKeysOnNewLine": true, | ||
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true }, | ||
@@ -67,4 +89,40 @@ "requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true }, | ||
"mark": "'" | ||
} | ||
}, | ||
"disallowOperatorBeforeLineBreak": [], | ||
"requireSpaceBeforeKeywords": [ | ||
"do", | ||
"for", | ||
"if", | ||
"else", | ||
"switch", | ||
"case", | ||
"try", | ||
"catch", | ||
"finally", | ||
"while", | ||
"with", | ||
"return" | ||
], | ||
"validateAlignedFunctionParameters": { | ||
"lineBreakAfterOpeningBraces": true, | ||
"lineBreakBeforeClosingBraces": true | ||
}, | ||
"requirePaddingNewLinesBeforeExport": true, | ||
"validateNewlineAfterArrayElements": { | ||
"maximum": 1 | ||
}, | ||
"requirePaddingNewLinesAfterUseStrict": true, | ||
"disallowArrowFunctions": true, | ||
"disallowMultiLineTernary": true, | ||
"validateOrderInObjectKeys": "asc-insensitive" | ||
} | ||
@@ -0,1 +1,9 @@ | ||
1.1.0 / 2015-10-02 | ||
================= | ||
* [Fix] Some browsers report TypedArray constructors as `typeof object` | ||
* [New] return false for "class" constructors, when possible. | ||
* [Tests] up to `io.js` `v3.3`, `node` `v4.1` | ||
* [Dev Deps] update `eslint`, `editorconfig-tools`, `nsp`, `tape`, `semver`, `jscs`, `covert`, `make-arrow-function` | ||
* [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG | ||
1.0.4 / 2015-01-30 | ||
@@ -2,0 +10,0 @@ ================= |
@@ -15,6 +15,9 @@ 'use strict'; | ||
var genClass = '[object GeneratorFunction]'; | ||
var constructorRegex = /\s*class /; | ||
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; | ||
module.exports = function isCallable(value) { | ||
if (typeof value !== 'function') { return false; } | ||
if (!value) { return false; } | ||
if (typeof value !== 'function' && typeof value !== 'object') { return false; } | ||
if (constructorRegex.test(value)) { return false; } | ||
if (hasToStringTag) { return tryFunctionObject(value); } | ||
@@ -21,0 +24,0 @@ var strClass = toStr.call(value); |
{ | ||
"name": "is-callable", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"author": "Jordan Harband", | ||
@@ -9,8 +9,8 @@ "description": "Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.", | ||
"scripts": { | ||
"test": "npm run lint && node --harmony --es-staging test.js && npm run security", | ||
"test": "npm run lint && node --es-staging test.js && npm run security", | ||
"coverage": "covert test.js", | ||
"coverage-quiet": "covert test.js --quiet", | ||
"lint": "npm run jscs && npm run eslint", | ||
"jscs": "jscs test.js *.js", | ||
"eslint": "eslint test.js *.js", | ||
"jscs": "jscs *.js", | ||
"eslint": "eslint *.js", | ||
"eccheck": "editorconfig-tools check *.js **/*.js > /dev/null", | ||
@@ -37,14 +37,13 @@ "security": "nsp package" | ||
"devDependencies": { | ||
"foreach": "~2.0.5", | ||
"is": "~2.2.0", | ||
"tape": "~3.4.0", | ||
"indexof": "~0.0.1", | ||
"covert": "1.0.0", | ||
"jscs": "~1.10.0", | ||
"editorconfig-tools": "~0.0.1", | ||
"nsp": "~1.0.0", | ||
"eslint": "~0.13.0", | ||
"make-arrow-function": "~1.0.0", | ||
"make-generator-function": "~1.0.0", | ||
"semver": "~4.2.0" | ||
"tape": "^4.2.0", | ||
"covert": "^1.1.0", | ||
"jscs": "^2.2.1", | ||
"editorconfig-tools": "^0.1.1", | ||
"nsp": "^1.1.0", | ||
"eslint": "^1.5.1", | ||
"@ljharb/eslint-config": "^1.2.0", | ||
"make-arrow-function": "^1.1.0", | ||
"make-generator-function": "^1.1.0", | ||
"semver": "^5.0.3", | ||
"foreach": "^2.0.5" | ||
}, | ||
@@ -51,0 +50,0 @@ "testling": { |
@@ -46,3 +46,3 @@ # is-callable <sup>[![Version Badge][2]][1]</sup> | ||
[1]: https://npmjs.org/package/is-callable | ||
[2]: http://vb.teelaun.ch/ljharb/is-callable.svg | ||
[2]: http://versionbadg.es/ljharb/is-callable.svg | ||
[3]: https://travis-ci.org/ljharb/is-callable.svg | ||
@@ -49,0 +49,0 @@ [4]: https://travis-ci.org/ljharb/is-callable |
75
test.js
@@ -8,8 +8,21 @@ 'use strict'; | ||
var arrowFn = require('make-arrow-function')(); | ||
var forEach = require('foreach'); | ||
var classConstructor; | ||
try { | ||
/* eslint-disable no-new-func */ | ||
var makeClassConstructor = Function('"use strict"; return class Foo {}'); | ||
/* eslint-enable no-new-func */ | ||
classConstructor = makeClassConstructor(); | ||
} catch (e) {/**/} | ||
test('not callables', function (t) { | ||
t.notOk(isCallable(), 'undefined is not callable'); | ||
t.notOk(isCallable(null), 'null is not callable'); | ||
t.notOk(isCallable(false), 'false is not callable'); | ||
t.notOk(isCallable(true), 'true is not callable'); | ||
t.test('non-number/string primitives', function (st) { | ||
st.notOk(isCallable(), 'undefined is not callable'); | ||
st.notOk(isCallable(null), 'null is not callable'); | ||
st.notOk(isCallable(false), 'false is not callable'); | ||
st.notOk(isCallable(true), 'true is not callable'); | ||
st.end(); | ||
}); | ||
t.notOk(isCallable([]), 'array is not callable'); | ||
@@ -20,8 +33,17 @@ t.notOk(isCallable({}), 'object is not callable'); | ||
t.notOk(isCallable(new Date()), 'new Date() is not callable'); | ||
t.notOk(isCallable(42), 'number is not callable'); | ||
t.notOk(isCallable(Object(42)), 'number object is not callable'); | ||
t.notOk(isCallable(NaN), 'NaN is not callable'); | ||
t.notOk(isCallable(Infinity), 'Infinity is not callable'); | ||
t.notOk(isCallable('foo'), 'string primitive is not callable'); | ||
t.notOk(isCallable(Object('foo')), 'string object is not callable'); | ||
t.test('numbers', function (st) { | ||
st.notOk(isCallable(42), 'number is not callable'); | ||
st.notOk(isCallable(Object(42)), 'number object is not callable'); | ||
st.notOk(isCallable(NaN), 'NaN is not callable'); | ||
st.notOk(isCallable(Infinity), 'Infinity is not callable'); | ||
st.end(); | ||
}); | ||
t.test('strings', function (st) { | ||
st.notOk(isCallable('foo'), 'string primitive is not callable'); | ||
st.notOk(isCallable(Object('foo')), 'string object is not callable'); | ||
st.end(); | ||
}); | ||
t.end(); | ||
@@ -32,4 +54,7 @@ }); | ||
var fn = function () { return 3; }; | ||
var fakeFunction = { valueOf: function () { return fn; }, toString: function () { return String(fn); } }; | ||
fakeFunction[Symbol.toStringTag] = function () { return 'Function'; }; | ||
var fakeFunction = { | ||
toString: function () { return String(fn); }, | ||
valueOf: function () { return fn; } | ||
}; | ||
fakeFunction[Symbol.toStringTag] = 'Function'; | ||
t.notOk(isCallable(fakeFunction), 'fake Function with @@toStringTag "Function" is not callable'); | ||
@@ -39,2 +64,14 @@ t.end(); | ||
var typedArrayNames = [ | ||
'Int8Array', | ||
'Uint8Array', | ||
'Uint8ClampedArray', | ||
'Int16Array', | ||
'Uint16Array', | ||
'Int32Array', | ||
'Uint32Array', | ||
'Float32Array', | ||
'Float64Array' | ||
]; | ||
test('Functions', function (t) { | ||
@@ -46,2 +83,11 @@ t.ok(isCallable(function () {}), 'function is callable'); | ||
test('Typed Arrays', function (st) { | ||
forEach(typedArrayNames, function (typedArray) { | ||
if (typeof global[typedArray] !== 'undefined') { | ||
st.ok(isCallable(global[typedArray]), typedArray + ' is callable'); | ||
} | ||
}); | ||
st.end(); | ||
}); | ||
test('Generators', { skip: !genFn }, function (t) { | ||
@@ -56,1 +102,6 @@ t.ok(isCallable(genFn), 'generator function is callable'); | ||
}); | ||
test('"Class" constructors', { skip: !classConstructor }, function (t) { | ||
t.notOk(isCallable(classConstructor), 'class constructors are not callable'); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11
193
17982
1