Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.0] - 2026-01-31

### Added

- Async validation support for server-side checks like username availability or email verification
- Configurable concurrency limit for async validators to prevent overwhelming servers
- `requiredIf(condition)` method for all validators to conditionally require fields
- New number validator with constraints for min, max, integer, positive, negative, decimal places, and more
- New array validator with constraints for length, uniqueness, and item inclusion checks
- New date validator with constraints for ranges, past/future, weekday/weekend, and age calculations

### Changed

- All validators now accept `null` or `undefined` values gracefully, skipping validation unless `required()` is called
- String validator's `prepare()` method now supports chaining multiple preprocessing operations

## [1.2.0] - 2026-01-28

### Added
Expand Down
316 changes: 316 additions & 0 deletions docs/assets/index-9DKjRuDa.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/assets/index-Bq4AALX0.css

This file was deleted.

1 change: 1 addition & 0 deletions docs/assets/index-CCOdL3LA.css

Large diffs are not rendered by default.

274 changes: 0 additions & 274 deletions docs/assets/index-VALo2x4L.js

This file was deleted.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" href="favicon.png" />
<title>svstate demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="module" crossorigin src="/svstate/assets/index-VALo2x4L.js"></script>
<link rel="stylesheet" crossorigin href="/svstate/assets/index-Bq4AALX0.css">
<script type="module" crossorigin src="/svstate/assets/index-9DKjRuDa.js"></script>
<link rel="stylesheet" crossorigin href="/svstate/assets/index-CCOdL3LA.css">
</head>

<body>
Expand Down
50 changes: 25 additions & 25 deletions docs/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const {
state: { errors, hasErrors, isDirty }
} = createSvState(sourceData, {
validator: (source) => ({
username: stringValidator(source.username, 'trim').required().minLength(3).maxLength(20).noSpace().getError(),
email: stringValidator(source.email, 'trim').required().email().getError(),
username: stringValidator(source.username).prepare('trim').required().minLength(3).maxLength(20).noSpace().getError(),
email: stringValidator(source.email).prepare('trim').required().email().getError(),
age: numberValidator(source.age).required().min(18).max(120).integer().getError(),
bio: stringValidator(source.bio).maxLength(200).getError(),
website: stringValidator(source.website, 'trim').website('required').getError()
website: stringValidator(source.website).prepare('trim').website('required').getError()
})
});
```
Expand Down Expand Up @@ -68,18 +68,18 @@ const {
state: { errors, hasErrors, isDirty }
} = createSvState(sourceData, {
validator: (source) => ({
name: stringValidator(source.name, 'trim').required().minLength(2).maxLength(50).getError(),
name: stringValidator(source.name).prepare('trim').required().minLength(2).maxLength(50).getError(),
address: {
street: stringValidator(source.address.street, 'trim').required().minLength(5).getError(),
city: stringValidator(source.address.city, 'trim').required().minLength(2).getError(),
zip: stringValidator(source.address.zip, 'trim').required().minLength(5).maxLength(10).getError()
street: stringValidator(source.address.street).prepare('trim').required().minLength(5).getError(),
city: stringValidator(source.address.city).prepare('trim').required().minLength(2).getError(),
zip: stringValidator(source.address.zip).prepare('trim').required().minLength(5).maxLength(10).getError()
},
company: {
name: stringValidator(source.company.name, 'trim').required().minLength(2).getError(),
department: stringValidator(source.company.department, 'trim').maxLength(50).getError(),
name: stringValidator(source.company.name).prepare('trim').required().minLength(2).getError(),
department: stringValidator(source.company.department).prepare('trim').maxLength(50).getError(),
contact: {
phone: stringValidator(source.company.contact.phone, 'trim').required().minLength(10).getError(),
email: stringValidator(source.company.contact.email, 'trim').required().email().getError()
phone: stringValidator(source.company.contact.phone).prepare('trim').required().minLength(10).getError(),
email: stringValidator(source.company.contact.email).prepare('trim').required().email().getError()
}
}
})
Expand Down Expand Up @@ -118,14 +118,14 @@ const {
state: { errors, hasErrors, isDirty }
} = createSvState(sourceData, {
validator: (source) => ({
listName: stringValidator(source.listName, 'trim').required().minLength(2).getError(),
listName: stringValidator(source.listName).prepare('trim').required().minLength(2).getError(),
items: arrayValidator(source.items).required().minLength(1).getError(),
...Object.fromEntries(
source.items.map((item, index) => [
`item_${index}`,
{
name: stringValidator(item.name, 'trim').required().minLength(2).getError(),
email: stringValidator(item.email, 'trim').required().email().getError()
name: stringValidator(item.name).prepare('trim').required().minLength(2).getError(),
email: stringValidator(item.email).prepare('trim').required().email().getError()
}
])
)
Expand Down Expand Up @@ -176,7 +176,7 @@ const {
state: { errors, hasErrors, isDirty }
} = createSvState(sourceData, {
validator: (source) => ({
productName: stringValidator(source.productName, 'trim').required().minLength(2).getError(),
productName: stringValidator(source.productName).prepare('trim').required().minLength(2).getError(),
item: {
unitPrice: numberValidator(source.item.unitPrice).required().positive().getError(),
quantity: numberValidator(source.item.quantity).required().integer().min(1).max(100).getError()
Expand Down Expand Up @@ -217,10 +217,10 @@ const {
state: { errors, hasErrors, isDirty, snapshots }
} = createSvState(sourceData, {
validator: (source) => ({
firstName: stringValidator(source.firstName, 'trim').required().minLength(2).maxLength(30).getError(),
lastName: stringValidator(source.lastName, 'trim').required().minLength(2).maxLength(30).getError(),
email: stringValidator(source.email, 'trim').required().email().getError(),
phone: stringValidator(source.phone, 'trim').required().minLength(10).getError(),
firstName: stringValidator(source.firstName).prepare('trim').required().minLength(2).maxLength(30).getError(),
lastName: stringValidator(source.lastName).prepare('trim').required().minLength(2).maxLength(30).getError(),
email: stringValidator(source.email).prepare('trim').required().email().getError(),
phone: stringValidator(source.phone).prepare('trim').required().minLength(10).getError(),
bio: stringValidator(source.bio).maxLength(200).getError()
}),
effect: ({ snapshot, property }) => {
Expand Down Expand Up @@ -271,10 +271,10 @@ const {
state: { errors, hasErrors, isDirty }
} = createSvState(sourceData, {
validator: (source) => ({
firstName: stringValidator(source.firstName, 'trim').required().minLength(2).maxLength(30).getError(),
lastName: stringValidator(source.lastName, 'trim').required().minLength(2).maxLength(30).getError(),
email: stringValidator(source.email, 'trim').required().email().getError(),
phone: stringValidator(source.phone, 'trim').required().minLength(10).getError(),
firstName: stringValidator(source.firstName).prepare('trim').required().minLength(2).maxLength(30).getError(),
lastName: stringValidator(source.lastName).prepare('trim').required().minLength(2).maxLength(30).getError(),
email: stringValidator(source.email).prepare('trim').required().email().getError(),
phone: stringValidator(source.phone).prepare('trim').required().minLength(10).getError(),
bio: stringValidator(source.bio).maxLength(200).getError()
})
});
Expand Down Expand Up @@ -308,8 +308,8 @@ const {
state: { errors, hasErrors, isDirty, actionInProgress, actionError }
} = createSvState(sourceData, {
validator: (source) => ({
title: stringValidator(source.title, 'trim').required().minLength(3).maxLength(50).getError(),
description: stringValidator(source.description, 'trim').required().minLength(10).maxLength(200).getError()
title: stringValidator(source.title).prepare('trim').required().minLength(3).maxLength(50).getError(),
description: stringValidator(source.description).prepare('trim').required().minLength(10).maxLength(200).getError()
}),
action: async () => {
await new Promise((resolve) => setTimeout(resolve, 500));
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svstate",
"version": "1.2.0",
"version": "1.3.0",
"description": "Supercharged $state() for Svelte 5: deep reactive proxy with validation, cross-field rules, computed & side-effects",
"author": "BCsabaEngine",
"license": "ISC",
Expand Down