Skip to content

Commit

Permalink
feat(checks): add isPromise() & isPromiseLike()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 8, 2018
1 parent fb4f309 commit 9900e99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/checks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export * from "./is-object";
export * from "./is-odd";
export * from "./is-plain-object";
export * from "./is-positive";
export * from "./is-promise";
export * from "./is-promiselike";
export * from "./is-regexp";
export * from "./is-safari";
export * from "./is-string";
Expand Down
3 changes: 3 additions & 0 deletions packages/checks/src/is-promise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isPromise(x: any): x is Promise<any> {
return x instanceof Promise;
}
6 changes: 6 additions & 0 deletions packages/checks/src/is-promiselike.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { implementsFunction } from "./implements-function";

export function isPromiseLike(x: any): x is Promise<any> {
return x instanceof Promise ||
(implementsFunction(x, "then") && implementsFunction(x, "catch"));
}

0 comments on commit 9900e99

Please sign in to comment.