Skip to content
Merged
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
25 changes: 14 additions & 11 deletions isFunction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import getTag from './.internal/getTag.js'
import isObject from './isObject.js'

/**
* Checks if `value` is classified as a `Function` object.
Expand All @@ -10,21 +8,26 @@ import isObject from './isObject.js'
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
* @example
*
* isFunction(_)
* isFunction(class Any{})
* // => true
*
* isFunction(() => {})
* // => true
*
* isFunction(async () => {})
* // => true
*
* isFunction(function * Any() {})
* // => true
*
* isFunction(Math.round)
* // => true
*
* isFunction(/abc/)
* // => false
*/
function isFunction(value) {
if (!isObject(value)) {
return false
}
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 9 which returns 'object' for typed arrays and other constructors.
const tag = getTag(value)
return tag == '[object Function]' || tag == '[object AsyncFunction]' ||
tag == '[object GeneratorFunction]' || tag == '[object Proxy]'
return typeof value === 'function'
}

export default isFunction