Skip to content

Commit

Permalink
feat: add isBoolean function
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeMeDev authored and DoHyeong Lee committed Jun 30, 2022
1 parent 63eb7bc commit c74281a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import isArray from "./isArray";
import isEmpty from "./isEmpty";
import isNil from "./isNil";
import isNumber from "./isNumber";
import isBoolean from "./isBoolean";
import isObject from "./isObject";
import isString from "./isString";
import isUndefined from "./isUndefined";
Expand Down Expand Up @@ -82,6 +83,7 @@ export {
isEmpty,
isNil,
isNumber,
isBoolean,
isObject,
isString,
isUndefined,
Expand Down
15 changes: 15 additions & 0 deletions src/isBoolean.ts
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;
16 changes: 16 additions & 0 deletions test/isBoolean.spec.ts
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);
});
});
14 changes: 14 additions & 0 deletions type-check/isBoolean.test.ts
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>(),
]);

0 comments on commit c74281a

Please sign in to comment.