Repository navigation
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']; // stringSmall 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
- is-kit: toStandardSchema API Reference
- Standard Schema specification
- TanStack Form: Validation
- Implementation: #485
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! π
narrowKeyTobase-guard short-circuit behavior: #476arrayOfsparse-array and short-circuit behavior: #477setOfiteration order and short-circuit behavior: #478orevaluation order and error propagation: #479defineboolean coercion semantics: #480lazycaching after predicate invocation errors: #482- Nullish wrapper short-circuit behavior: #483
mapOfkey/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.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