-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Returns true if `n` is a Boolean. | ||
* | ||
* @example | ||
* ```ts | ||
* isBoolean(true); // true | ||
* isBoolean(null); // false | ||
* isBoolean("FxTS"); // false | ||
* ``` | ||
*/ | ||
function isBoolean(n: unknown): n is boolean { | ||
return typeof n === "boolean"; | ||
} | ||
|
||
export default isBoolean; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { isBoolean } from "../src/index"; | ||
|
||
describe("isBoolean", function () { | ||
it.each([undefined, null, 1, "1", Symbol("a"), () => null])( | ||
"given non boolean then should return false", | ||
function (s) { | ||
const result = isBoolean(s); | ||
expect(result).toEqual(false); | ||
}, | ||
); | ||
|
||
it("given boolean then should return true", function () { | ||
const result = isBoolean(true); | ||
expect(result).toEqual(true); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as Test from "../src/types/Test"; | ||
import { isBoolean, pipe } from "../src"; | ||
|
||
const { checks, check } = Test; | ||
|
||
const res1 = isBoolean(true); | ||
const res2 = isBoolean("a"); | ||
const res3 = pipe(true, isBoolean); | ||
|
||
checks([ | ||
check<typeof res1, boolean, Test.Pass>(), | ||
check<typeof res2, boolean, Test.Pass>(), | ||
check<typeof res3, boolean, Test.Pass>(), | ||
]); |