Skip to content

Commit

Permalink
feat: add result
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Oct 31, 2018
1 parent 32f4fc1 commit 6242783
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export { default as preventEventDefault } from './preventEventDefault'
export { default as randomString } from './randomString'
export { default as reduce } from './reduce'
export { default as repeat } from './repeat'
export { default as result } from './result'
export { default as shuffle } from './shuffle'
export { default as stopEventPropagation } from './stopEventPropagation'
export { default as storage } from './storage'
Expand Down
12 changes: 12 additions & 0 deletions src/result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import isFunction from './isFunction'

/**
* 如果 `value` 是函数,返回函数执行后的值;否则,直接返回 `value`。
*
* @param value 要解析的值
* @param args 如果 `value` 是函数,传递给它的参数
* @returns 解析后的值
*/
export default function result(value: any, ...args: any[]): any {
return isFunction(value) ? value.apply(null, args) : value
}

0 comments on commit 6242783

Please sign in to comment.