Skip to content

Commit

Permalink
chore(docs): add future to array (#22)
Browse files Browse the repository at this point in the history
* chore(docs): add future section to array

* chore(lib): export tuple
  • Loading branch information
Kosai106 authored Nov 23, 2024
1 parent 6e7c355 commit d4f9818
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions apps/docs/pages/schemas/array.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@ try {
} catch (error) {
console.error('Parsing failed:', error.message);
}
```

## Future

In one of the next upcoming releases, the `Array` schema will support mixed schemas, so you'd be able to for example do the following:

```ts
import { array, string, number } from '@nordic-ui/validathor';

const arrayRule = array([string(), number()]);

try {
const parsedValue = arrayRule.parse(['Hello', 42, 'world']);
console.log('Parsed value:', parsedValue);
} catch (error) {
console.error('Parsing failed:', error.message);
}
```
1 change: 1 addition & 0 deletions packages/validathor/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { number } from './number'
export { object } from './object'
export { regex } from './regex'
export { string } from './string'
export { tuple } from './tuple'
2 changes: 1 addition & 1 deletion packages/validathor/src/schemas/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const tuple = <T extends Parser<unknown>[]>(
},
): Parser<T[]> => ({
name: 'tuple' as const,
parse: (value: unknown): T[] => {
parse: (value): T[] => {
assert(
Array.isArray(value),
new TypeError(message?.type_error || ERROR_CODES.ERR_TYP_0000.message()),
Expand Down

0 comments on commit d4f9818

Please sign in to comment.