https://github.com/alloc/zod-file
https://github.com/alloc/zod-file
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/alloc/zod-file
- Owner: alloc
- Archived: true
- Created: 2023-01-20T22:29:59.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-20T22:35:06.000Z (about 3 years ago)
- Last Synced: 2025-03-24T21:02:34.588Z (11 months ago)
- Language: TypeScript
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# zod-file
[](https://www.npmjs.com/package/zod-file)
[](https://github.com/prettier/prettier)
[](https://paypal.me/alecdotbiz)
> Binary and base64 validators
### Usage
Extend `zod` with a custom module, like `src/zod.ts` in your project:
```ts
export * from 'zod'
export * from 'zod-file'
```
Use it in your schema:
```ts
import * as z from './zod'
const User = z.object({
avatar: z.base64(),
})
const parsedUser = User.parse({
// Pass a buffer or a base64 string.
avatar: fs.readFileSync('avatar.png'),
})
// Receive a base64 string.
const base64Avatar = parsedUser.avatar
// Invalid base64 strings will throw.
User.parse({
avatar: 'not base64',
})
```