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 ensure

Ensures/asserts that the given value is an instance of the given type and then returns that value.

import { ensure } from '@knudsen/assert'

const user = await fetchUser()
const profileImage = ensure(response.profileImage, 'profileImage')

console.log(profileImage) // profileImage is now non-nullable

Type Parameters

Parameters

value: T

The value to check for being an instance of the given type.

optional
messageOrName: string

An optional message or name for the assertion.

Return Type

NonNullable<T>

Add Package

deno add @knudsen/assert

Import symbol

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

Add Package

npx jsr add @knudsen/assert

Import symbol

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

Add Package

yarn dlx jsr add @knudsen/assert

Import symbol

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

Add Package

pnpm dlx jsr add @knudsen/assert

Import symbol

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

Add Package

bunx jsr add @knudsen/assert

Import symbol

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