https://github.com/codemonument/deno_zod_semver
A simple deno module by @codemonument with a zod schema for validating semver. Uses official regex and is cross-posted to npm as zod-semver
https://github.com/codemonument/deno_zod_semver
Last synced: 3 months ago
JSON representation
A simple deno module by @codemonument with a zod schema for validating semver. Uses official regex and is cross-posted to npm as zod-semver
- Host: GitHub
- URL: https://github.com/codemonument/deno_zod_semver
- Owner: codemonument
- License: mit
- Created: 2023-04-27T09:49:48.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-31T22:50:15.000Z (about 2 years ago)
- Last Synced: 2025-01-25T15:41:25.090Z (over 1 year ago)
- Language: TypeScript
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Zod SemVer
[](https://jsr.io/@codemonument/zod-semver/)
[
](https://www.npmjs.com/package/zod-semver)
A simple deno module by @codemonument with a zod schema for validating semver.
Uses official regex.
> [!WARNING]
> Not published to ~~[deno.land/x/zod_semver](https://deno.land/x/zod_semver)~~ anymore! Use the jsr package instead:
> `jsr:@codemonument/zod-semver`!
## Usage
### Import in Deno
```bash
deno add @codemonument/zod-semver
```
```ts
import {ZodSemver} from '@codemonument/zod-semver';
```
### Import in Node
```bash
npm add @codemonument/zod-semver
```
```ts
import {ZodSemver} from 'zod-semver';
```
### Usage after Import
```ts
// Use like any other Zod Schema:
ZodSemver.parse('1.0.0');
// Or include in another Zod Schema like this:
const MyObjectSchema = z.object({
version: ZodSemver,
name: z.string(),
age: z.number().optional(),
});
```
## Using the branded ZodSemver type
At it's base, the ZodSemver type is simply a more refined string. So the TS type for it is string.
However, sometimes it might be useful for a function to make sure that it only receives an already parsed semver string.
This is possible via the branded `ZodSemver` type.
'branded' means that the type is a string, but with a special property atached that makes it unique.
See the zod docs for more information:
## Links
| Name | Target |
| -------- | ----------------------------------------------- |
| Git Repo | https://github.com/codemonument/deno_zod_semver |
| JSR | https://jsr.io/@codemonument/zod-semver/ |
| NPM | https://www.npmjs.com/package/zod-semver |
## Create new version of this package (for maintainers)
1. Update CHANGELOG.md with your changes
2. Run `deno task uv `
3. Run `deno task test`
4. Commit changes & add git tag for your version
5. Push changes & tags => github actions will deploy