
Research
/Security News
Mini Shai-Hulud Campaign Hits Red Hat Cloud Services npm Packages
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.
@xylabs/assert
Advanced tools
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
Using npm:
npm install {{name}}
Using yarn:
yarn add {{name}}
Using pnpm:
pnpm add {{name}}
Using bun:
bun add {{name}}
See the LICENSE file for license rights and limitations (LGPL-3.0-only).
### .temp-typedoc
### functions
### <a id="assertDefinedEx"></a>assertDefinedEx
Implementation of assertDefinedEx that handles all overloads.
function assertDefinedEx<T>(expr, messageFunc?): T;
Asserts that a value is defined (not undefined) and returns the value. Throws an error if the value is undefined.
T
The type of value to check
T | undefined
Expression to be evaluated for being defined
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, errorFunc?): T;
Asserts that a value is defined (not undefined) and returns the value. Throws a custom error if the value is undefined.
T
The type of value to check
R extends Error
The type of error to throw
T | undefined
Expression to be evaluated for being defined
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'))
### <a id="assertEx"></a>assertEx
Implementation of assertEx that handles all overloads.
function assertEx<T>(expr, messageFunc?): T;
Asserts that an expression is truthy and returns the value. Throws an error if the expression is falsy.
T
The type of value to check
T | null | undefined
Expression to be evaluated for truthiness
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, errorFunc?): T;
Asserts that an expression is truthy and returns the value. Throws a custom error if the expression is falsy.
T
The type of value to check
R extends Error
The type of error to throw
T | null | undefined
Expression to be evaluated for truthiness
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'))
FAQs
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
The npm package @xylabs/assert receives a total of 6,884 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.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.

Security News
The Rust project is moving toward formal rules on LLM use in contributions after months of internal debate over maintainer burden, code quality, and contributor experience.