Home / Function/ stringValidator() — astro Function Reference

stringValidator() — astro Function Reference

Architecture documentation for the stringValidator() function in validators.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  88ee635a_01f9_6df7_6fb7_d77a70d01f58["stringValidator()"]
  507d4b59_27b6_fc34_cbc8_02ec1d1596e5["validators.ts"]
  88ee635a_01f9_6df7_6fb7_d77a70d01f58 -->|defined in| 507d4b59_27b6_fc34_cbc8_02ec1d1596e5
  9f0736b8_fe2c_7232_075d_3effa18267d9["selectValidator()"]
  9f0736b8_fe2c_7232_075d_3effa18267d9 -->|calls| 88ee635a_01f9_6df7_6fb7_d77a70d01f58
  style 88ee635a_01f9_6df7_6fb7_d77a70d01f58 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/env/validators.ts lines 31–73

	({ max, min, length, url, includes, startsWith, endsWith }: StringSchema): ValueValidator =>
	(input) => {
		if (typeof input !== 'string') {
			return {
				ok: false,
				errors: ['type'],
			};
		}
		const errors: Array<string> = [];

		if (max !== undefined && !(input.length <= max)) {
			errors.push('max');
		}
		if (min !== undefined && !(input.length >= min)) {
			errors.push('min');
		}
		if (length !== undefined && !(input.length === length)) {
			errors.push('length');
		}
		if (url !== undefined && !URL.canParse(input)) {
			errors.push('url');
		}
		if (includes !== undefined && !input.includes(includes)) {
			errors.push('includes');
		}
		if (startsWith !== undefined && !input.startsWith(startsWith)) {
			errors.push('startsWith');
		}
		if (endsWith !== undefined && !input.endsWith(endsWith)) {
			errors.push('endsWith');
		}

		if (errors.length > 0) {
			return {
				ok: false,
				errors,
			};
		}
		return {
			ok: true,
			value: input,
		};
	};

Domain

Subdomains

Called By

Frequently Asked Questions

What does stringValidator() do?
stringValidator() is a function in the astro codebase, defined in packages/astro/src/env/validators.ts.
Where is stringValidator() defined?
stringValidator() is defined in packages/astro/src/env/validators.ts at line 31.
What calls stringValidator()?
stringValidator() is called by 1 function(s): selectValidator.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free