@9oelm/maybe
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

maybe

npm i --save @9oelm/maybe

yarn add @9oelm/maybe

Just my personal util for handling null and undefined.

Usage

import { maybe } from '@9oelm/maybe'

const mayBeNullOrUndefined: HTMLElement | null = document.querySelector('#maybe-exists');

const text: string = 
  maybe(maybeNullOrUndefined)
  .then(({ innerText }) => innerText)
  .otherwise(`please fill out text first`);

// omit .then to just receive the defined value itself
const someHTMLElementOrMyFallbackHtmlElement: HTMLElement = 
  maybe(mayBeNullOrUndefined).otherwise(document.createElement('div'))

Readme

Keywords

none

Package Sidebar

Install

npm i @9oelm/maybe

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

9.11 kB

Total Files

8

Last publish

Collaborators

  • 9oelm