Skip to content

Commit

Permalink
👍 isObjectOf allows function object
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Apr 14, 2024
1 parent 748257e commit 51091e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,11 @@ export function isObjectOf<
}
return setPredicateFactoryMetadata(
(x: unknown): x is ObjectOf<T> => {
if (x == null || typeof x !== "object" || Array.isArray(x)) return false;
if (
x == null ||
typeof x !== "object" && typeof x !== "function" ||
Array.isArray(x)
) return false;
// Check each values
for (const k in predObj) {
if (!predObj[k]((x as T)[k])) return false;
Expand Down
7 changes: 7 additions & 0 deletions is_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,13 @@ Deno.test("isObjectOf<T>", async (t) => {
true,
"Object have an unknown property",
);
assertEquals(
isObjectOf(predObj)(
Object.assign(() => void 0, { a: 0, b: "a", c: true }),
),
true,
"Function object",
);
});
await t.step("returns false on non T object", () => {
const predObj = {
Expand Down

0 comments on commit 51091e2

Please sign in to comment.