Skip to main content

Built and signed on GitHub Actions

This package works with Bun, Cloudflare Workers, Node.js, Deno, Browsers
JSR Score
100%
Published
3 months ago (0.1.0)
function assertTruthy

Useful for type narrowing assertions.

Type Parameters

Parameters

value: T

The value to check for being truthy.

optional
messageOrName: string

An optional message or name for the assertion.

declare const x: number | string | undefined;
assertTruthy(x) // number | string

// Also usable with type guarding expressions!
assertTruthy(typeof x === "string"); // Narrows x to string

Return Type

asserts value

Add Package

deno add @knudsen/assert

Import symbol

import { assertTruthy } from "@knudsen/assert";

Add Package

npx jsr add @knudsen/assert

Import symbol

import { assertTruthy } from "@knudsen/assert";

Add Package

yarn dlx jsr add @knudsen/assert

Import symbol

import { assertTruthy } from "@knudsen/assert";

Add Package

pnpm dlx jsr add @knudsen/assert

Import symbol

import { assertTruthy } from "@knudsen/assert";

Add Package

bunx jsr add @knudsen/assert

Import symbol

import { assertTruthy } from "@knudsen/assert";