valibot-schema-semver
Version:
Valibot schema for Semantic Versioning
47 lines (33 loc) • 1.71 kB
Markdown
# valibot-schema-semver
> Valibot schema for [Semantic Versioning](https://semver.org/).
[](https://github.com/idleberg/valibot-schemas/blob/main/LICENSE)
[](https://www.npmjs.org/package/valibot-schema-semver)
[](https://jsr.io/@idleberg/valibot-schema-semver)
[](https://github.com/idleberg/valibot-schemas/actions/workflows/node.yml)
> [!NOTE]
> This libray isn't as lightweight as most built-in Valibot schemas, so it might not be suitable for some use-cases.
## Installation
```shell
# NodeJS
npm install valibot-schema-semver
# Deno
deno add jsr:@idleberg/valibot-schema-semver
```
## Usage
```javascript
import * as v from "valibot";
import { semver, semverRange } from "valibot-schema-semver";
const PackageJsonSchema = v.object({
name: v.pipe(v.string(), v.minLength(1), v.max(214)),
version: semver(),
engines: v.object({
node: semverRange(),
}),
});
```
For simple version validation, you can also use a lightweight variant (~350B instead of 25kB). This uses the [official regular expression](https://regex101.com/r/vkijKf/1/) rather than the [parser by npm](https://www.npmjs.com/package/semver).
```javascript
import { semver } from "valibot-schema-semver/light";
```
## License
This work is licensed under [The MIT License](LICENSE).