This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ node_modules
44.nyc_output /
55coverage /
66npm-debug.log
7+ package-lock.json
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import swapCase from './swap-case'
3434import endsWith from './endsWith'
3535import round from './round'
3636import checkPalindrome from './checkPalindrome'
37+ import isFunction from './is-function'
3738
3839export {
3940 isEven ,
@@ -72,4 +73,5 @@ export {
7273 endsWith ,
7374 round ,
7475 checkPalindrome ,
76+ isFunction ,
7577}
Original file line number Diff line number Diff line change 1+ export default isFunction
2+
3+ /**
4+ * Original source: https://stackoverflow.com/a/7356528/3344977
5+ *
6+ * This method checks whether an object passed as an
7+ * argument is a javascript Function or not
8+ * @param {Object } functionToCheck - the object to check
9+ * @return {Boolean } - true if functionToCheck is a function else false
10+ */
11+ function isFunction ( functionToCheck ) {
12+ const getType = { }
13+ return functionToCheck && getType . toString . call ( functionToCheck ) === '[object Function]'
14+ }
Original file line number Diff line number Diff line change 1+ import test from 'ava'
2+ import { isFunction } from '../src'
3+
4+ test ( 'check a function' , t => {
5+ const func = ( ) => { }
6+ const expected = true
7+ const actual = isFunction ( func )
8+ t . deepEqual ( actual , expected )
9+ } )
10+
11+ test ( 'check an object' , t => {
12+ const object = { }
13+ const expected = false
14+ const actual = isFunction ( object )
15+ t . deepEqual ( actual , expected )
16+ } )
17+
18+ test ( 'check a string' , t => {
19+ const string = 'string'
20+ const expected = false
21+ const actual = isFunction ( string )
22+ t . deepEqual ( actual , expected )
23+ } )
24+
25+ test ( 'check a boolean' , t => {
26+ const boolean = true
27+ const expected = false
28+ const actual = isFunction ( boolean )
29+ t . deepEqual ( actual , expected )
30+ } )
31+
32+ test ( 'check a number' , t => {
33+ const number = 1
34+ const expected = false
35+ const actual = isFunction ( number )
36+ t . deepEqual ( actual , expected )
37+ } )
You can’t perform that action at this time.
0 commit comments