-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor(vest-utils): Predicates: Support boolean value
- Loading branch information
Showing
2 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { isEmpty } from 'isEmpty'; | ||
import optionalFunctionValue from 'optionalFunctionValue'; | ||
|
||
export type Predicate<T> = (value: T) => boolean; | ||
export type Predicate<T> = boolean | ((value: T) => boolean); | ||
|
||
export function all<T = any>(...p: Predicate<T>[]): (value: T) => boolean { | ||
return (value: T) => | ||
isEmpty(p) ? false : p.every(predicate => predicate(value)); | ||
isEmpty(p) | ||
? false | ||
: p.every(predicate => optionalFunctionValue(predicate, value)); | ||
} | ||
|
||
export function any<T = any>(...p: Predicate<T>[]): (value: T) => boolean { | ||
return (value: T) => | ||
isEmpty(p) ? false : p.some(predicate => predicate(value)); | ||
isEmpty(p) | ||
? false | ||
: p.some(predicate => optionalFunctionValue(predicate, value)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
484baec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vest – ./website
vest-ealush.vercel.app
vest.vercel.app
vestjs.dev
vest-git-latest-ealush.vercel.app
www.vestjs.dev
484baec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vest-next – ./website
vest-next-ealush.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-website.vercel.app
vest-next.vercel.app