Skip to content

Commit

Permalink
docs: add basic usage documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleShit committed Jul 13, 2024
1 parent b6ce629 commit 36bfd5f
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
11 changes: 10 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@
"useTabs": true,
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "all",
"overrides": [
{
"files": "*.md",
"options": {
"useTabs": false,
"tabWidth": 2
}
}
]
}
80 changes: 79 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
# Bodek

A zod-like schema validator
A zod-like schema validator, 100% type-safe.

Made for fun and learning purposes.

## Installation

```bash
npm i bodek
```

## Usage

The API is basically the same as [Zod](https://zod.dev/)'s, but only with the core functionality (again, learning purposes...)

### `parse`:

```typescript
import { b } from 'bodek';

const schema = b.object({
name: b.string().min(3).max(10),
age: b.number().min(18),
});

// No errors
schema.parse({
name: 'John',
age: 30,
});

// Throws an error
schema.parse({
name: 'John',
age: 10,
});
```

### `safeParse`:

```typescript
import { b } from 'bodek';

const schema = b.object({
name: b.string().min(3).max(10),
age: b.number().min(18),
});

const { success, data, error } = schema.safeParse({
name: 'John',
age: 30,
});

if (success) {
console.log(data);
} else {
console.error(error);
}
```

### `refine`:

```typescript
import { b } from 'bodek';

const schema = b.object({
name: b
.string()
.min(3)
.max(10)
.refine((name) => name.toLowerCase() !== 'john', 'Name cannot be John'),
age: b.number().min(18),
});

// Throws an error
schema.parse({
name: 'John',
age: 30,
});
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bodek",
"description": "A zod-like schema validator ",
"description": "A zod-like schema validator, 100% type-safe",
"version": "0.0.0",
"author": "StyleShit",
"license": "MIT",
Expand Down

0 comments on commit 36bfd5f

Please sign in to comment.