CtroEnv
ctroenvType-Safe Environment Variables
Getting StartedQuick StartCore Concepts
defineEnv()string()number()boolean()semver()pick()ip(), ipv4(), ipv6()uuid(), guid()Chainable MethodsRefinementsError HandlingSchema CompositionSecurityCustom Validators
CLI Overviewctroenv validatectroenv generatectroenv checkctroenv docsctroenv initCLI Configuration
Node AdapterVite AdapterNext.js Adapter
Migration from t3-envMigration from envalidMigration from dotenv

semver()

Create a strict semver validator that validates semantic version strings.

  1. Docs
  2. Core API

semver()

Creates a validator that accepts strict semver strings.

Signature

function semver(): SemverValidator

Accepted Values

Accepts semantic version strings in X.Y.Z format. No v prefix, no ranges (^, ~). Supports optional pre-release tags and build metadata.

InputResult
"1.0.0"✅ "1.0.0"
"0.0.1"✅ "0.0.1"
"999.999.999"✅ "999.999.999"
"1.2.3-alpha"✅ "1.2.3-alpha"
"1.2.3-alpha.1"✅ "1.2.3-alpha.1"
"1.2.3+build.1"✅ "1.2.3+build.1"
"1.2.3-rc.1+build.2"✅ "1.2.3-rc.1+build.2"
"v1.0.0"❌ Invalid — v prefix not allowed
"1.0"❌ Invalid — must have three parts
"^1.0.0"❌ Invalid — range not allowed
"abc"❌ Type error — not a semver string

Refinements

semver() has no type-specific refinements. It supports only the chainable methods (.optional(), .default(), .describe(), .secret(), .validate()).

Examples

Basic semver

const env = defineEnv({
  APP_VERSION: semver(),
})
// env.APP_VERSION: string

With defaults

const env = defineEnv({
  API_VERSION: semver().default("1.0.0"),
})
// env.API_VERSION: string (default: "1.0.0")

Optional

const env = defineEnv({
  SCHEMA_VERSION: semver().optional(),
})
// env.SCHEMA_VERSION: string | undefined

How is this guide?

Edit on GitHub

Last updated on Jun 25, 2026

Previousboolean()Nextpick()

On this page

SignatureAccepted ValuesRefinementsExamplesBasic semverWith defaultsOptional