We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
isBigInt
1 parent fac0c61 commit 0e9677bCopy full SHA for 0e9677b
is.ts
@@ -17,6 +17,13 @@ export function isNumber(x: unknown): x is number {
17
return typeof x === "number";
18
}
19
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
+
27
/**
28
* Return `true` if the type of `x` is `boolean`.
29
*/
@@ -225,6 +232,7 @@ export function isOneOf<T extends readonly Predicate<unknown>[]>(
225
232
export default {
226
233
String: isString,
227
234
Number: isNumber,
235
+ BigInt: isBigInt,
228
236
Boolean: isBoolean,
229
237
Array: isArray,
230
238
ArrayOf: isArrayOf,
is_test.ts
@@ -5,6 +5,7 @@ import {
5
import is, {
6
isArray,
7
isArrayOf,
8
+ isBigInt,
9
isBoolean,
10
isFunction,
11
isInstanceOf,
@@ -24,6 +25,7 @@ import is, {
const examples = {
string: ["", "Hello world"],
number: [0, 1234567890],
+ bigint: [0n, 1234567890n],
boolean: [true, false],
30
array: [[], [0, 1, 2], ["a", "b", "c"], [0, "a", true]],
31
record: [{}, { a: 0, b: 1, c: 2 }, { a: "a", b: "b", c: "c" }],
@@ -34,6 +36,7 @@ const examples = {
34
36
35
37
function stringify(x: unknown): string {
38
if (typeof x === "function") return x.toString();
39
+ if (typeof x === "bigint") return `${x}n`;
40
return JSON.stringify(x);
41
42
@@ -63,6 +66,10 @@ Deno.test("isNumber", async (t) => {
63
66
await testWithExamples(t, isNumber, ["number"]);
64
67
});
65
68
69
+Deno.test("isBigInt", async (t) => {
70
+ await testWithExamples(t, isBigInt, ["bigint"]);
71
+});
72
73
Deno.test("isBoolean", async (t) => {
74
await testWithExamples(t, isBoolean, ["boolean"]);
75
0 commit comments