1.3.2 • Published 6 years ago

@katis/maybe v1.3.2

Weekly downloads
151
License
MIT
Repository
github
Last release
6 years ago

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)) {
  // ...
}
1.3.2

6 years ago

1.3.1

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago