is-kit offers a streamlined, zero-dependency solution for creating isFoo style type guards in TypeScript, enhancing code clarity and reducing boilerplate. With runtime safety, composability, and ergonomic design, it simplifies type checking and function definition, ensuring efficient development.
is-kit is a lightweight, zero-dependency toolkit designed for creating isFoo style type guards in TypeScript. This toolkit emphasizes runtime safety, composability, and user-friendly ergonomics, making it a powerful solution for developers looking to simplify type checking in their applications.
The is-kit toolkit enables developers to construct type guards from small, composable units with ease. For instance, here's how to use is-kit to define simple type guards:
import { define, predicateToRefine, and, or, not, isString, isNumber } from 'is-kit';
// 1. Define small pieces
const isShortString = define<string>(
(value) => isString(value) && value.length <= 3
);
const isPositive = predicateToRefine<number>((num) => num > 0);
// 2. Compose them
const isPositiveNumber = and(isNumber, isPositive);
const shortOrPositive = or(isShortString, isPositiveNumber);
const isOther = not(shortOrPositive);
// 3. Use them
shortOrPositive('foo'); // true
shortOrPositive(42); // true
isOther(false); // true
define<T>(fn) to transform a standard function into a type guard.predicateToRefine(fn) enhances your predicates by enabling type narrowing.and, or, not, and struct allow for building complex combinations seamlessly.nullable, optional, and safeParse are included for an improved developer experience.For detailed documentation, including runnable examples of each helper, please refer to the API Reference section of the documentation.
For anyone interested in contributing to is-kit, please refer to CONTRIBUTE.md for guidelines on the workflow, coding standards, and setup instructions. Contributions are welcomed!
Explore more about is-kit and transform the way type guards are handled in TypeScript projects.
No comments yet.
Sign in to be the first to comment.