Skip to content

Commit

Permalink
Merge pull request #65 from badrap/changeset-release/main
Browse files Browse the repository at this point in the history
Version Packages
  • Loading branch information
jviide authored Oct 16, 2024
2 parents 194dbfd + 99dbdd9 commit fdae912
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
17 changes: 0 additions & 17 deletions .changeset/silly-pigs-protect.md

This file was deleted.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @badrap/valita

## 0.3.11

### Patch Changes

- [`f78c082`](https://github.com/badrap/valita/commit/f78c0825b1a59d6f6cd7e73354526ee517a2bd0b) Thanks [@jviide](https://github.com/jviide)! - Add **experimental** support for `.optional(() => x)`

The `.optional()` method now supports _default value functions_ for replacing `undefined` and missing values from the input and wrapped validator. The functionality is similar to `.default(x)`, except that `defaultFn` has to be a function and is executed for each validation run. This allows patterns like the following:

```ts
const Item = v.object({ id: v.string() });

const Items = v.array(Item).optional(() => []);
```

This avoids a common pitfall with using `.default([])` for the same pattern. As the newly created empty arrays are not shared, mutating them is safe(r) as it doesn't affect other validation outputs.

This feature is marked **experimental** for the time being.

## 0.3.10

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@badrap/valita",
"version": "0.3.10",
"version": "0.3.11",
"exports": "./src/index.ts"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@badrap/valita",
"version": "0.3.10",
"version": "0.3.11",
"description": "A validation & parsing library for TypeScript",
"main": "./dist/cjs/index.js",
"module": "./dist/mjs/index.mjs",
Expand Down

0 comments on commit fdae912

Please sign in to comment.