Skip to main content
Home
This package has been archived, and as such it is read-only.

Built and signed on GitHub Actions

latest

A small, focused TypeScript library for safer code through functional patterns using natural language. Inspired by folktale.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a month ago (0.5.0)
type alias Nullable

Constructs a type that can be either a value or nothing.

This type is useful for representing optional values, similar to TypeScript's built-in optional properties, but as an explicit union type. It's particularly helpful when working with the Maybe type from folklore.

Examples

Example 1

// Function parameter that accepts a value or nothing
function greet(name: Nullable<string>): string {
  return name != null ? `Hello, ${name}!` : 'Hello, stranger!'
}

greet('Alice')     // "Hello, Alice!"
greet(null)        // "Hello, stranger!"
greet(undefined)   // "Hello, stranger!"

Example 2

// Converting nullable values to Maybe
import { Maybe } from '@folklore/folklore'

const value: Nullable<number> = Math.random() > 0.5 ? 42 : null
const maybeValue = Maybe.FromNullable(value)

Type Parameters

Type
  • The type of the value when it exists

Definition

See

  • Nothing for the absence value type

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@folklore/folklore

Import symbol

import { type Nullable } from "@folklore/folklore";
or

Import directly with a jsr specifier

import { type Nullable } from "jsr:@folklore/folklore";

Add Package

pnpm i jsr:@folklore/folklore
or (using pnpm 10.8 or older)
pnpm dlx jsr add @folklore/folklore

Import symbol

import { type Nullable } from "@folklore/folklore";

Add Package

yarn add jsr:@folklore/folklore
or (using Yarn 4.8 or older)
yarn dlx jsr add @folklore/folklore

Import symbol

import { type Nullable } from "@folklore/folklore";

Add Package

vlt install jsr:@folklore/folklore

Import symbol

import { type Nullable } from "@folklore/folklore";

Add Package

npx jsr add @folklore/folklore

Import symbol

import { type Nullable } from "@folklore/folklore";

Add Package

bunx jsr add @folklore/folklore

Import symbol

import { type Nullable } from "@folklore/folklore";