Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mityli

scobru224MIT1.0.2TypeScript support: included

A minimal runtime type-checking library for JavaScript using Valibot

runtime, type-checking, valibot, proxy, javascript

readme

MITYLI ⚓

mi-nimal type-checking library

A minimal JavaScript library providing runtime type-checking powered by Valibot.

Features

  • Automatic Schema Inference: Build Valibot schemas from arbitrary JavaScript values (primitives, arrays, objects)
  • One-Shot Validation: Validate any value against its inferred schema in a single call
  • Simple API: Just 3 core functions - parse(), inferSchema(), and validate()

One‑Shot Validation: Validate any value against its inferred schema in a single call.

Assignment Enforcement: Wrap validated data in a Proxy to intercept property and array-index assignments, ensuring all mutations conform to the original schema.

Installation

npm install mitili
# or
yarn add mitili

Usage

import { parse, inferSchema, validate } from 'mityli';

// 1️⃣ Infer and validate a value
const raw = { name: 'Alice', age: 30 };
const user = parse(raw);

console.log(user.name); // "Alice"

// 2️⃣ Safe assignments (via Proxy)
user.age = 31;    // OK
user.age = '31';  // throws ValiError: Expected number

// 3️⃣ Reuse schema for other data
const schema = inferSchema(raw);
try {
  const other = validate(schema, { name: 'Bob', age: '25' });
} catch (err) {
  console.error('Invalid data:', err);
}

API

inferSchema(value)

Infer a Valibot schema from any JS value.

validate(schema, data)

Validate a value against a given schema (alias to Valibot parse).

parse(value)

Infer, validate, and return a Proxy‑wrapped object/array for runtime assignment checks.

Contributing

Contributions, bug reports, and feature requests are welcome! Please open an issue or pull request on GitHub.

License

MIT