@ruffy/ts-optional

An Optional type inspired by Scala's Option for better undefined handling.

Usage no npm install needed!

<script type="module">
  import ruffyTsOptional from 'https://cdn.skypack.dev/@ruffy/ts-optional';
</script>

README

Node.js CI codecov

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

License

MIT