Skip to content

Commit

Permalink
Add isFunction method
Browse files Browse the repository at this point in the history
  • Loading branch information
mano8 committed Oct 20, 2023
1 parent 1890a91 commit a4f17b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export const ut = {
toFixedFloat: (fNum, fix = 2, defaultValue = null) => {
return (ut.isNumber(fNum) && ut.isNumber(fix)) ? parseFloat(fNum.toFixed(fix)) : defaultValue;
},
/**
* Test if value is a valid function
* @param value {object} The value to test
* @return {boolean} Return true if value is a valid function
*/
isFunction: (value) => {
return typeof value === "function"
},
/**
* Test if value is a valid object
* @param value {object} The value to test
Expand Down
10 changes: 10 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ test('test toFixedFloat method', () => {
expect(ut.toFixedFloat('hello', 2, 0)).toBe(0)
})

test('test isFunction method', () => {
const funcTest = ()=>{return true;}
expect(ut.isFunction(funcTest)).toBe(true)
expect(ut.isFunction({})).toBe(false)
expect(ut.isFunction({a: 1})).toBe(false)
expect(ut.isFunction("hello")).toBe(false)
expect(ut.isFunction(['a'])).toBe(false)
expect(ut.isFunction(2)).toBe(false)
})

test('test isObject method', () => {
expect(ut.isObject({})).toBe(true)
expect(ut.isObject({a: 1})).toBe(true)
Expand Down

0 comments on commit a4f17b8

Please sign in to comment.