Skip to content

Commit 0e9677b

Browse files
committed
👍 Add isBigInt
1 parent fac0c61 commit 0e9677b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

is.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export function isNumber(x: unknown): x is number {
1717
return typeof x === "number";
1818
}
1919

20+
/**
21+
* Return `true` if the type of `x` is `bigint`.
22+
*/
23+
export function isBigInt(x: unknown): x is bigint {
24+
return typeof x === "bigint";
25+
}
26+
2027
/**
2128
* Return `true` if the type of `x` is `boolean`.
2229
*/
@@ -225,6 +232,7 @@ export function isOneOf<T extends readonly Predicate<unknown>[]>(
225232
export default {
226233
String: isString,
227234
Number: isNumber,
235+
BigInt: isBigInt,
228236
Boolean: isBoolean,
229237
Array: isArray,
230238
ArrayOf: isArrayOf,

is_test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import is, {
66
isArray,
77
isArrayOf,
8+
isBigInt,
89
isBoolean,
910
isFunction,
1011
isInstanceOf,
@@ -24,6 +25,7 @@ import is, {
2425
const examples = {
2526
string: ["", "Hello world"],
2627
number: [0, 1234567890],
28+
bigint: [0n, 1234567890n],
2729
boolean: [true, false],
2830
array: [[], [0, 1, 2], ["a", "b", "c"], [0, "a", true]],
2931
record: [{}, { a: 0, b: 1, c: 2 }, { a: "a", b: "b", c: "c" }],
@@ -34,6 +36,7 @@ const examples = {
3436

3537
function stringify(x: unknown): string {
3638
if (typeof x === "function") return x.toString();
39+
if (typeof x === "bigint") return `${x}n`;
3740
return JSON.stringify(x);
3841
}
3942

@@ -63,6 +66,10 @@ Deno.test("isNumber", async (t) => {
6366
await testWithExamples(t, isNumber, ["number"]);
6467
});
6568

69+
Deno.test("isBigInt", async (t) => {
70+
await testWithExamples(t, isBigInt, ["bigint"]);
71+
});
72+
6673
Deno.test("isBoolean", async (t) => {
6774
await testWithExamples(t, isBoolean, ["boolean"]);
6875
});

0 commit comments

Comments
 (0)