metaplex-foundation / umi

A Solana Framework for JS Clients.
https://umi.typedoc.metaplex.com
MIT License
168 stars 51 forks source link

add wrapNullish() as an available option #153

Closed tonyboylehub closed 3 weeks ago

tonyboylehub commented 3 weeks ago

wrapNullable didn't account for an undefined input and would result in a return value of some(undefined) causing isNone checks to not pass if undefined was the nullable value.

export const wrapNullable = <T>(nullable: Nullable<T>): Option<T> =>
  nullable !== null ? some(nullable) : none<T>();

Added a wrapNullish function to check for both null and undefined which will return the value of none() if null or undefined is the presented nullish value.

export const wrapNullish = <T>(nullish: Nullish<T>): Option<T> =>
  nullish !== null && nullish !== undefined ? some(nullish) : none<T>();
changeset-bot[bot] commented 3 weeks ago

🦋 Changeset detected

Latest commit: f9033faf62b896b8b85d31138ce1b832200846ea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages | Name | Type | | --------------------------------------------------- | ----- | | @metaplex-foundation/umi-options | Major | | @metaplex-foundation/umi-serializers | Major | | @metaplex-foundation/umi | Major | | @metaplex-foundation/umi-bundle-defaults | Major | | @metaplex-foundation/umi-bundle-tests | Major | | @metaplex-foundation/umi-downloader-http | Major | | @metaplex-foundation/umi-eddsa-web3js | Major | | @metaplex-foundation/umi-http-fetch | Major | | @metaplex-foundation/umi-program-repository | Major | | @metaplex-foundation/umi-rpc-chunk-get-accounts | Major | | @metaplex-foundation/umi-rpc-web3js | Major | | @metaplex-foundation/umi-serializer-beet | Major | | @metaplex-foundation/umi-serializer-data-view | Major | | @metaplex-foundation/umi-signer-derived | Major | | @metaplex-foundation/umi-signer-wallet-adapters | Major | | @metaplex-foundation/umi-storage-mock | Major | | @metaplex-foundation/umi-transaction-factory-web3js | Major | | @metaplex-foundation/umi-uploader-aws | Major | | @metaplex-foundation/umi-uploader-bundlr | Major | | @metaplex-foundation/umi-uploader-irys | Major | | @metaplex-foundation/umi-uploader-nft-storage | Major | | @metaplex-foundation/umi-web3js-adapters | Major |

Not sure what this means? Click here to learn what changesets are.

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/metaplex-foundation/umi/new/feat/add-option-wrapNullish?filename=.changeset/forty-ladybugs-chew.md&value=---%0A%22%40metaplex-foundation%2Fumi-options%22%3A%20patch%0A---%0A%0Aadd%20wrapNullish()%20as%20an%20available%20option%0A)

vercel[bot] commented 3 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
umi-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2024 9:13pm
tonyboylehub commented 3 weeks ago

@blockiosaurus before I merge this are we happy that all these packages are going up a major release?

blockiosaurus commented 3 weeks ago

Yup that's fine by me.