https://github.com/mrdrogdrog/optional
https://github.com/mrdrogdrog/optional
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mrdrogdrog/optional
- Owner: mrdrogdrog
- License: mit
- Created: 2022-06-23T15:32:12.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-15T01:53:41.000Z (over 1 year ago)
- Last Synced: 2025-03-15T02:35:56.589Z (over 1 year ago)
- Language: TypeScript
- Size: 7.99 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Authors: AUTHORS.md
Awesome Lists containing this project
README
# Optional
This library provides java-like optionals to filter, map and process values depending on if they're present or not.
I created this lib because I like functional programming think that Optionals are a good way to clean up code.
Yes, I know that typescript has the optional operator (`?`) but sometimes this isn't enough, like when I want to filter values or fail instantly if a value is empty.
## How to use
Install it with yarn or npm using `yarn add @mrdrogdrog/optional` or `npm i @mrdrogdrog/optional`.
## API
In addition to the [traditional java-like optional functions](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html) I added some more useful functions like
[isEmpty](https://github.com/mrdrogdrog/optional/blob/main/docs/Optional.md#isempty), [orThrow](https://github.com/mrdrogdrog/optional/blob/main/docs/Optional.md#orthrow) and [guard](https://github.com/mrdrogdrog/optional/blob/main/docs/Optional.md#guard).
Check the [docs](https://github.com/mrdrogdrog/optional/tree/main/docs) folder for the whole API.
## Build
You can build this lib by running `yarn build`.
Run tests with `yarn test`.
To check the code style use `yarn lint`.
## Contributions
I welcome contributions!
Have a look at the [contribution docs](CONTRIBUTING.md) to find out how you can help.
# License
Licensed under MIT. For our list of contributors, see [AUTHORS](AUTHORS).