PitchHut logo
Lightweight, zero-dependency toolkit for building `isFoo` type guards in TypeScript ✨
Pitch

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.

Description

Overview

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.

is-kit logo

Key Features

  • Minimal Boilerplate: Reduce repetitive code and improve maintainability by leveraging utility functions.
  • Type Safety: Ensures that type guards are robust, fostering confidence in type checks across the codebase.
  • Composability: Create complex type guards by combining simple, reusable pieces, enhancing flexibility and readability.
  • Zero Dependencies: No external libraries are required, allowing for a lightweight and efficient implementation.

Quick Start

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

Core Concepts

  • Define Once: Use define<T>(fn) to transform a standard function into a type guard.
  • Upgrade Predicates: predicateToRefine(fn) enhances your predicates by enabling type narrowing.
  • Compose Freely: Functions such as and, or, not, and struct allow for building complex combinations seamlessly.
  • Stay Ergonomic: Helper methods like nullable, optional, and safeParse are included for an improved developer experience.

API Reference

For detailed documentation, including runnable examples of each helper, please refer to the API Reference section of the documentation.

Get Involved

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.

0 comments

No comments yet.

Sign in to be the first to comment.