New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@katis/maybe

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@katis/maybe

Library for handling possibly undefined values

1.3.2
latest
Source
npm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

maybe

FAQs

Package last updated on 13 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts