
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
type-guardians
Advanced tools
A lightweight, zero-dependency TypeScript library providing type guards and assertions for safer and more readable code
Type Guardian is a lightweight, zero-dependency TypeScript library that provides a collection of type guards and assertions to help you write safer and more readable code.
Install the package using your favorite package manager:
npm install type-guardians
# or
yarn add type-guardians
# or
pnpm add type-guardians
Type Guardian offers two types of functions for each data type: is functions for type guarding and assert functions for type assertions.
is functionsis functions are type guards that return a boolean value indicating whether the input value is of the expected type. You can use them in if statements to narrow down the type of a variable.
import { isString } from "type-guardians/string";
function greet(name: unknown) {
if (isString(name)) {
// name is now of type string
console.log(`Hello, ${name}!`);
} else {
console.log("Hello, guest!");
}
}
assert functionsassert functions are assertions that throw a TypeError if the input value is not of the expected type. You can use them to ensure that a variable has a certain type before using it. You can also provide a custom error message as an optional second parameter.
import { assertNumber } from "type-guardians/number";
function double(value: unknown) {
assertNumber(value);
// value is now of type number
return value * 2;
}
isString(value: unknown): value is stringassertString(value: unknown, message?: string): asserts value is stringisNumber(value: unknown): value is numberassertNumber(value: unknown, message?: string): asserts value is numberisError(value: unknown): value is ErrorassertError(value: unknown, message?: string): asserts value is ErrorFAQs
A lightweight, zero-dependency TypeScript library providing type guards and assertions for safer and more readable code
We found that type-guardians demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.