This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

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

1.3.2 • Public • Published

Maybe

This is a small library for handling potentially undefined values in TypeScript.

Api

import * as Maybe from '@katis/maybe'

const value: string | undefined = 'defined'

// map (or its alias mapDefined)
const length: number | undefined = Maybe.map(value, s => s.length)

// filter (or its alias filterDefined)
const shortString: string | undefined = Maybe.filter(value, s => s.length <= 3)

// orNull
const nullable: string | null = Maybe.orNull('nullable')

// fromNullable
const undefinedString: string | undefined = Maybe.fromNullable(nullable)

// getOrThrow
const neverReached: string = Maybe.getOrThrow<string>(undefined)

// getOrDefault
const defaulted: string = Maybe.getOrDefault<string>(undefined, 'default')

// getOrElse
const alternative: number = Maybe.getOrElse<number>(undefined, () => Date.now())

// isDefined
if (Maybe.isDefined(undefined)) {
  // ...
}

// notDefined
if (Maybe.notDefined(undefined)) {
  // ...
}

Package Sidebar

Install

npm i @katis/maybe

Weekly Downloads

0

Version

1.3.2

License

MIT

Unpacked Size

7.24 kB

Total Files

6

Last publish

Collaborators

  • katis