Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/object/index.ts>as

A JavaScript extension package for building strong and modern applications.
Latest
function as
import { as } from "https://deno.land/x/ayonli_jsext@v0.9.72/object/index.ts";

Checks if the value is an instance of the given type, returns the value itself if passed, otherwise returns null. This function is mainly used for the optional chaining syntax.

Examples

Example 1

import { as } from "@ayonli/jsext/object";

try {
    // ... do something
} catch (err) {
    console.error(as(err, Error)?.message ?? String(err));
}

Parameters

value: unknown
type: StringConstructor

Returns

string | null

Parameters

value: unknown
type: NumberConstructor

Returns

number | null

Parameters

value: unknown
type: BigIntConstructor

Returns

bigint | null

Parameters

value: unknown
type: BooleanConstructor

Returns

boolean | null

Parameters

value: unknown
type: SymbolConstructor

Returns

symbol | null

Parameters

value: unknown
type: Constructor<T>

Returns

T | null