@ruffy/ts-optional
v1.1.1
Published
An Optional type inspired by Scala's Option for better undefined handling.
Downloads
7,264
Maintainers
Readme
Optional
This repository provides an optional type that allows for cleaner code when dealing with operations that would otherwise return undefined
Features
Refer to the API documentation to see available classes and their functions.
Requirements
- Node and npm
- To build or develop you will benefit from having
npx
https://github.com/npm/npx. This allows invoking of the other global npm requirements in the repository (Typescript, Jest) without having to install them.
Usage
You can install the package using
npm i -S @ruffy/ts-optional
You can then use the classes direct as:
Optional.of(undefined) === None.nil
Optional.of(2) === new Some(2)
or you can use the provided helper functions for cleaner code:
optional(undefined) === none
optional(2) === some(2)
Contributing
Contributions, if they are in line with Monad logic are welcome. Requirements for pull requests are:
- All code is tested
- Naming is consistent with project naming
- Commits are squashed and contain commit messages according to RFC: Commit Message Guidelines