Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ var isArrowFnWithParensRegex = /^\([^\)]*\) *=>/;
var isArrowFnWithoutParensRegex = /^[^=]*=>/;

module.exports = function isArrowFunction(fn) {
if (!isCallable(fn)) { return false; }
var fnStr = fnToStr.call(fn);
return fnStr.length > 0 &&
!isNonArrowFnRegex.test(fnStr) &&
(isArrowFnWithParensRegex.test(fnStr) || isArrowFnWithoutParensRegex.test(fnStr));
var type = typeof fn;
if (!isCallable(fn) && type !== 'string') { return false; }
var fnStr = type === 'string' ? fn : fnToStr.call(fn);
return fnStr.length > 0 &&
!isNonArrowFnRegex.test(fnStr) &&
(isArrowFnWithParensRegex.test(fnStr) || isArrowFnWithoutParensRegex.test(fnStr));
};
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ test('returns true for arrow functions', function (t) {
}
t.end();
});

test('return true for arrow function in string', function (t) {
if (arrowFuncs.length > 0) {
t.ok(isArrowFunction('(a, b) => a * b'), 'arrow function in string');
} else {
t.skip('arrow function is arrow function - this environment does not support ES6 arrow functions. Please run `node --harmony`, or use a supporting browser.');
}
t.end();
});