Skip to main content

latest

Handling null and undefined in a unified manner, inspired by Rusts Result and Option types.

Works with
This package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Browsers
JSR Score
100%
Published
2 months ago (0.3.0)

Option

Package

For some projects I prefer handling null and undefined as one nil value, to make working with this easier I created this package. It was inspired by Rusts Options and Result types, so you can expect utility functions with similar behavior.

For usage, consult the docs. I tried to make them as clear as possible.

The package is developed and tested with Deno, I have marked other engines as compatible as I do not use any Deno specific features and expect the package in any environment.

Examples

Example 1

import { assertEquals } from "https://deno.land/std@0.106.0/testing/asserts.ts";
import { match } from './mod.ts';

const m1 = match(0).is(0); // true
assertEquals(m1, true);

const m2 = match(0).is(1); // false
assertEquals(m2, false);

Add Package

deno add @marv/option

Import symbol

import * as mod from "@marv/option";

Add Package

npx jsr add @marv/option

Import symbol

import * as mod from "@marv/option";

Add Package

yarn dlx jsr add @marv/option

Import symbol

import * as mod from "@marv/option";

Add Package

pnpm dlx jsr add @marv/option

Import symbol

import * as mod from "@marv/option";

Add Package

bunx jsr add @marv/option

Import symbol

import * as mod from "@marv/option";