Skip to content

Commit

Permalink
Merge pull request #44 from lambdalisue/add-is-unknown
Browse files Browse the repository at this point in the history
👍 Add `isUnknown` predicate function
  • Loading branch information
lambdalisue authored Nov 26, 2023
2 parents 8f8d181 + aec15fc commit 6cdf1e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export function isAny(_x: unknown): _x is any {
return true;
}

/**
* Always return `true` regardless of the type of `x`.
*/
export function isUnknown(_x: unknown): _x is unknown {
return true;
}

/**
* Return `true` if the type of `x` is `string`.
*/
Expand Down Expand Up @@ -508,6 +515,7 @@ export function isOptionalOf<T>(

export default {
Any: isAny,
Unknown: isUnknown,
String: isString,
Number: isNumber,
BigInt: isBigInt,
Expand Down
21 changes: 21 additions & 0 deletions is_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import is, {
isTupleOf,
isUndefined,
isUniformTupleOf,
isUnknown,
Predicate,
PredicateType,
} from "./is.ts";
Expand Down Expand Up @@ -135,6 +136,26 @@ Deno.test("isAny", async (t) => {
});
});

Deno.test("isUnknown", async (t) => {
await testWithExamples(t, isUnknown, {
validExamples: [
"string",
"number",
"bigint",
"boolean",
"array",
"record",
"syncFunction",
"asyncFunction",
"null",
"undefined",
"symbol",
"date",
"promise",
],
});
});

Deno.test("isString", async (t) => {
await testWithExamples(t, isString, { validExamples: ["string"] });
});
Expand Down

0 comments on commit 6cdf1e3

Please sign in to comment.