Skip to content

Commit

Permalink
Skip Uint8Arrays on unwrapOptionRecursively (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Aug 25, 2023
1 parent e5a1385 commit 05a4bdd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-otters-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@metaplex-foundation/umi-options': patch
---

Skip Uint8Arrays on unwrapOptionRecursively
7 changes: 5 additions & 2 deletions packages/umi-options/src/unwrapOptionRecursively.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ export function unwrapOptionRecursively<T, U = null>(
input: T,
fallback?: () => U
): UnwrappedOption<T, U> {
// Because null passes `typeof input === 'object'`.
if (!input) return input as UnwrappedOption<T, U>;
// Types to bypass.
if (!input || ArrayBuffer.isView(input)) {
return input as UnwrappedOption<T, U>;
}

const next = <X>(x: X) =>
(fallback
? unwrapOptionRecursively(x, fallback)
Expand Down
6 changes: 6 additions & 0 deletions packages/umi-options/test/unwrapOptionRecursively.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ test('it can unwrap options recursively', (t) => {
t.is(unwrapOptionRecursively(null), null);
t.is(unwrapOptionRecursively(undefined), undefined);

// TypedArrays.
t.deepEqual(
unwrapOptionRecursively(new Uint8Array([1, 2, 3])),
new Uint8Array([1, 2, 3])
);

// Functions.
const fn = () => 42;
t.is(unwrapOptionRecursively(fn), fn);
Expand Down

0 comments on commit 05a4bdd

Please sign in to comment.