Skip to content

v1.17.0

Latest

Choose a tag to compare

@nyaomaru nyaomaru released this 27 Nov 16:49
· 8 commits to main since this release
Immutable release. Only release title and notes can be modified.
e671e20

is-kit v1.17.0 is out! πŸŽ‰πŸ˜Έ

This release brings Standard Schema v1 support to is-kit, opening the door to a much wider TypeScript ecosystem while keeping is-kit small, simple, and guard-first.

We also received 9 community contributions that make our runtime contracts clearer, better documented, and more reliable! πŸ™Œ

πŸ”₯ Introducing toStandardSchema

Standard Schema is a common interface designed to make TypeScript validation libraries interoperable.

Instead of requiring ecosystem tools to support every validation library individually, Standard Schema provides a shared validation contract.

Starting with v1.17.0, you can turn any existing is-kit guard into a Standard Schema-compatible validator.

Getting started

import { isString, toStandardSchema } from 'is-kit';

const schema = toStandardSchema(isString);

schema['~standard'].validate('hello');
// { value: 'hello' }

schema['~standard'].validate(42);
// { issues: [{ message: 'Invalid value' }] }

Input and output types are preserved, too!

type SchemaTypes = NonNullable<
  typeof schema['~standard']['types']
>;

type Input = SchemaTypes['input'];   // string
type Output = SchemaTypes['output']; // string

Small implementation, wider possibilities

The adapter itself is intentionally simple.

export function toStandardSchema<T>(
  guard: Guard<T>
): GuardSchema<T> {
  return {
    '~standard': {
      version: 1,
      vendor: 'is-kit',
      validate: (value) =>
        guard(value)
          ? { value }
          : { issues: [{ message: 'Invalid value' }] }
    }
  };
}
  • Zero additional dependencies.
  • Synchronous validation.
  • Original values are preserved.
  • Input and output types are inferred.
  • Exceptions thrown by guards propagate unchanged.
  • Validation failures return a generic issue without a field path.

No new schema system. No transformation pipeline. Just a small bridge between existing is-kit guards and the Standard Schema ecosystem. 🐈

Example: TanStack Form

You can now use existing is-kit guards with tools such as TanStack Form.

import { useForm } from '@tanstack/react-form';
import {
  isString,
  struct,
  toStandardSchema
} from 'is-kit';

const isUser = struct({
  name: isString
});

const userSchema = toStandardSchema(isUser);

function useUserForm() {
  return useForm({
    defaultValues: {
      name: ''
    },
    validators: {
      onChange: userSchema
    },
    onSubmit: async ({ value }) => {
      console.log(value);
    }
  });
}

And your original guard remains available for ordinary TypeScript narrowing, filtering, and composition.

if (isUser(input)) {
  input.name; // string
}

const validUsers = users.filter(isUser);

Use guards where guards make sense, and Standard Schema where interoperability matters.

Learn more

Thank You, Contributors! πŸŽ‰

It's always exciting to see contributors return and continue improving is-kit.

  • @daocuong11 contributed an incredible 8 documentation improvements in this release! πŸ™Œ

    • narrowKeyTo base-guard short-circuit behavior: #476
    • arrayOf sparse-array and short-circuit behavior: #477
    • setOf iteration order and short-circuit behavior: #478
    • or evaluation order and error propagation: #479
    • define boolean coercion semantics: #480
    • lazy caching after predicate invocation errors: #482
    • Nullish wrapper short-circuit behavior: #483
    • mapOf key/value evaluation order: #484

    Thank you for making so many of our small runtime guarantees easier to discover and understand! πŸ˜ΈπŸ’š

  • @Lil-Clanky returned with additional regression coverage and documentation for equalsKey, clarifying missing-key behavior, own-property checks, and support for null-prototype objects.

    #458

    Thank you for continuing to help make is-kit more predictable and reliable! πŸˆπŸ™Œ

What's Changed

  • docs(changelog): 1.16.6 by @github-actions[bot] in #463
  • test(core): cover equalsKey missing-key behavior with undefined target by @Lil-Clanky in #458
  • docs(key): note narrowKeyTo base-guard short-circuit behavior (#475) by @daocuong11 in #476
  • docs(array-of): document sparse-array and short-circuit behavior (#464) by @daocuong11 in #477
  • docs(set-of): document iteration order and short-circuit behavior (#466) by @daocuong11 in #478
  • docs(define): document boolean coercion semantics (#473) by @daocuong11 in #480
  • docs(lazy): clarify caching after predicate invocation errors by @daocuong11 in #482
  • docs(nullish): document wrapper short-circuit behavior by @daocuong11 in #483
  • docs(logic): document or evaluation order and short-circuit behavior (#467) by @daocuong11 in #479
  • docs(mapOf): document key/value evaluation and short-circuit behavior by @daocuong11 in #484
  • feat: add Standard Schema adapter by @nyaomaru in #485
  • Release: 1.17.0 by @github-actions[bot] in #486

Full Changelog: v1.16.6...v1.17.0