
Security News
TC39 Advances Temporal to Stage 4 Alongside Several ECMAScript Proposals
TC39’s March 2026 meeting advanced eight ECMAScript proposals, including Temporal reaching Stage 4 and securing its place in the ECMAScript 2026 specification.
@xylabs/assert
Advanced tools
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
@xylabs/assert
| Function | Description |
|---|---|
| assertDefinedEx | Implementation of assertDefinedEx that handles all overloads. |
| assertEx | Implementation of assertEx that handles all overloads. |
Implementation of assertDefinedEx that handles all overloads.
function assertDefinedEx<T>(expr: T | undefined, messageFunc?: AssertExMessageFunc<T>): T;
Asserts that a value is defined (not undefined) and returns the value. Throws an error if the value is undefined.
| Type Parameter | Description |
|---|---|
T | The type of value to check |
| Parameter | Type | Description |
|---|---|---|
expr | T | undefined | Expression to be evaluated for being defined |
messageFunc? | AssertExMessageFunc<T> | Function that returns a message for the error if expression is undefined |
T
The value of the expression (guaranteed to be defined)
Error with the message returned by messageFunc
// Simple usage with a message function
const value = assertDefinedEx(possiblyUndefined, () => 'Value must be defined')
// Using with type narrowing
const config: Config | undefined = loadConfig()
const safeConfig = assertDefinedEx(config, () => 'Config failed to load')
// safeConfig is now type Config (not Config | undefined)
function assertDefinedEx<T, R>(expr: T | undefined, errorFunc?: AssertExErrorFunc<T, R>): T;
Asserts that a value is defined (not undefined) and returns the value. Throws a custom error if the value is undefined.
| Type Parameter | Description |
|---|---|
T | The type of value to check |
R extends Error | The type of error to throw |
| Parameter | Type | Description |
|---|---|---|
expr | T | undefined | Expression to be evaluated for being defined |
errorFunc? | AssertExErrorFunc<T, R> | Function that returns a custom error instance if expression is undefined |
T
The value of the expression (guaranteed to be defined)
Custom error returned by errorFunc
// Using with a custom error
const user = assertDefinedEx(getUser(), () => new UserNotFoundError('User not found'))
Implementation of assertEx that handles all overloads.
function assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T;
Asserts that an expression is truthy and returns the value. Throws an error if the expression is falsy.
| Type Parameter | Description |
|---|---|
T | The type of value to check |
| Parameter | Type | Description |
|---|---|---|
expr | T | null | undefined | Expression to be evaluated for truthiness |
messageFunc? | AssertExMessageFunc<T> | Function that returns a message for the error if expression is falsy |
T
The value of the expression (guaranteed to be truthy)
Error with the message returned by messageFunc
// Simple usage with a message function
const value = assertEx(possiblyFalsy, () => 'Value must be truthy')
// Using with type narrowing
const config: Config | null = loadConfig()
const safeConfig = assertEx(config, () => 'Config failed to load')
// safeConfig is now type Config (not Config | null)
function assertEx<T, R>(expr: T | null | undefined, errorFunc?: AssertExErrorFunc<T, R>): T;
Asserts that an expression is truthy and returns the value. Throws a custom error if the expression is falsy.
| Type Parameter | Description |
|---|---|
T | The type of value to check |
R extends Error | The type of error to throw |
| Parameter | Type | Description |
|---|---|---|
expr | T | null | undefined | Expression to be evaluated for truthiness |
errorFunc? | AssertExErrorFunc<T, R> | Function that returns a custom error instance if expression is falsy |
T
The value of the expression (guaranteed to be truthy)
Custom error returned by errorFunc
// Using with a custom error
const user = assertEx(getUser(), () => new UserNotFoundError('User not found'))
Part of sdk-js
See the LICENSE file for license details
FAQs
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
The npm package @xylabs/assert receives a total of 2,638 weekly downloads. As such, @xylabs/assert popularity was classified as popular.
We found that @xylabs/assert demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
TC39’s March 2026 meeting advanced eight ECMAScript proposals, including Temporal reaching Stage 4 and securing its place in the ECMAScript 2026 specification.

Research
/Security News
Since January 31, 2026, we identified at least 72 additional malicious Open VSX extensions, including transitive GlassWorm loader extensions targeting developers.

Research
Six malicious Packagist packages posing as OphimCMS themes contain trojanized jQuery that exfiltrates URLs, injects ads, and loads FUNNULL-linked redirects.