https://github.com/scobru/mityli
A minimal runtime type-checking library for JavaScript using Valibot
https://github.com/scobru/mityli
library schema type-check type-validation valibot validation
Last synced: 17 days ago
JSON representation
A minimal runtime type-checking library for JavaScript using Valibot
- Host: GitHub
- URL: https://github.com/scobru/mityli
- Owner: scobru
- Created: 2025-05-18T15:26:30.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-06-15T09:23:14.000Z (11 months ago)
- Last Synced: 2025-10-20T07:49:03.954Z (6 months ago)
- Topics: library, schema, type-check, type-validation, valibot, validation
- Language: JavaScript
- Homepage:
- Size: 126 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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
```bash
npm install mitili
# or
yarn add mitili
```
## Usage
```js
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