Skip to content

Commit

Permalink
cellify: fix Object detection (#18)
Browse files Browse the repository at this point in the history
* cellify: fix Object detection

* cellify: revert to v.constructor.prototype

* cellify: fix format
  • Loading branch information
hbbio committed Feb 5, 2024
1 parent 0eebe23 commit 2b2b820
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/cellify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ test("fix point", async () => {
expect(u).toEqual(v);
}
});

test("_cellify one", async () => {
const sheet = new Sheet();
const proxy = new SheetProxy(sheet);
const res = _cellify(proxy, { a: 1 });
const cell = await res.get();
await expect(cell.a.get()).resolves.toBe(1);
});
5 changes: 3 additions & 2 deletions src/cellify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const _cellify = <T>(proxy: SheetProxy, v: T): Cellified<T> => {
? v.map((vv) => _cellify(proxy, vv), "cellify.[]")
: typeof v === "object" &&
v !== null &&
v?.constructor?.prototype !== Object.prototype // exclude classes
v.constructor.prototype === Object.prototype // exclude classes
? Object.fromEntries(
Object.entries(v).map(
([k, vv]) => [k, _cellify(proxy, vv)],
Expand Down Expand Up @@ -65,12 +65,13 @@ export const _uncellify = async <T>(
if (
typeof value === "object" &&
value !== null &&
v?.constructor?.prototype === Object.prototype
value.constructor.prototype === Object.prototype // exclude classes
)
return Object.fromEntries(
await Promise.all(
Object.entries(value).map(async ([k, vv]) => [k, await _uncellify(vv)])
)
);
// Classes, null or base types (string, number, ...)
return value as Uncellified<T>;
};

0 comments on commit 2b2b820

Please sign in to comment.