Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

katis/maybe-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

TypeScript library for handling potentially undefined values

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published