Skip to main content

Usage

There are two ways to import ts-belt functions into your project.

Compact

ModuleNamespaceDescription
ArrayAUtility functions for Array.
BooleanBUtility functions for Boolean.
NumberNUtility functions for Number.
Object (Dict)DUtility functions for Object.
StringSUtility functions for String.
GuardsGVarious TypeScript guards.
OptionOFunctions for handling the Option type that represents the existence and nonexistence of a value.
ResultRFunctions for describing the result of a certain operation without relying on exceptions.
FunctionFOther useful functions.

The full API reference can be found here.

import { A, O, N, pipe } from '@mobily/ts-belt'

pipe(
[1, 2, 3, 4, 5], // → [1, 2, 3, 4, 5]
A.dropExactly(2), // → Some([3, 4, 5])
O.flatMap(A.head), // → Some(3)
O.map(N.multiply(10)), // → Some(30)
O.getWithDefault(0), // → 30
) // → 30

Explicit

import * as Belt from '@mobily/ts-belt'

Belt.pipe(
[1, 2, 3, 4, 5],
Belt.A.dropExactly(2),
Belt.O.flatMap(Belt.A.head),
Belt.O.map(Belt.N.multiply(10)),
Belt.O.getWithDefault(0),
)