npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@board_tester/ts_maybe

v1.1.4

Published

utility for safe handling of null and undefined values

Downloads

3

Readme

ts_maybe

Nullability Helpers for TypeScript

Glossary

Usage

Installation:

npm install ts_maybe

Import

import { Maybe } from 'ts_maybe';

Create Maybe

const variable: number = 1;
Maybe.of(variable); //=> Just<number>(1)

const variable: number | undefined = undefined;
Maybe.of(variable); //=> Nothing

const variable: number | undefined = undefined;
const defaultValue: number = 0;
Maybe.of(variable, defaultValue); //=> Just<number>(0)

const variable: number | undefined = undefined;
const defaultValue: Maybe<number> = Maybe.of(5);
Maybe.of(variable, defaultValue); //=> Just<number>(5)

const variables: number[] = [ undefined, null, 2, 1];
Maybe.ofs(variables); //=> Just<number>(2) 

#deprecated, save use Maybe.of
const variable: string = 'hello';
Just(variable); //=> Just<string>('hello')

#deprecated, save use Maybe.of
const variable: string | undefined = undefined;
Just(variable); //=> throws Error
Nothing(); //=> Nothing

Documentation

Functions on Maybe instances

MaybeInstance.map(f: (value: T) => R) => Maybe<R>

  • f: Function for map T -> R

Returns Maybe[R]

MaybeInstance.fmap(f: (value: T) => Maybe<R>) => Maybe<R>

  • f: Function for fmap T -> Maybe[R]

Returns Maybe[R]

MaybeInstance.isJust() => type is Just

Returns Type is Just

MaybeInstance.isNothing() => type is Nothing

Returns Type is Nothing

MaybeInstance.if(f: (value: T) => void) => Maybe<T>

  • f: Function to compute with value if present

Returns Maybe[T]

MaybeInstance.else(f: () => void) => Maybe<T>

  • f: Function to compute if no value is present

Returns Maybe[T]

MaybeInstance.reset(f: (value: T) => void) => Nothing<T>

  • f: Function to compute with value if present, then reset to Nothing

Returns Nothing[T]

MaybeInstance.safe(f: () => T) => T

  • f: Function to compute to create returnValue if no value is present

Returns [T]

MaybeInstance.unsafe() => T

Returns [T] (throws Error if no value is present)

MaybeInstance.unwrap() => T | undefined

Returns [T] if value is present or undefined

MaybeInstance.or(ifNothing: Maybe<T> | T) => Maybe<T>

  • ifNothing: Value or Maybe if instance is Nothing

Returns Maybe[T]

Maybe.compare(left: Maybe<T>,right: Maybe<T>, comp: ((left: T, right: T) => boolean), onBothNothing?: boolean)

  • left : first Maybe
  • right: right Maybe
  • compo: Function to be calculated for comparison
  • onBothNothing: boolean to return if both Maybe's are Nothing

Returns boolean