-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from metaplex-foundation/feat/add-option-wrap…
…Nullish add wrapNullish() as an available option
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
'@metaplex-foundation/umi-options': minor | ||
--- | ||
|
||
`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. | ||
|
||
```ts | ||
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. | ||
|
||
```ts | ||
export const wrapNullish = <T>(nullish: Nullish<T>): Option<T> => | ||
nullish !== null && nullish !== undefined ? some(nullish) : none<T>(); | ||
``` | ||
|
||
- `Nullish` type added. | ||
- `wrapNullish` function added. | ||
- Tests for `wrapNullish` added. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters