Home / Function/ numberValidator() — astro Function Reference

numberValidator() — astro Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

packages/astro/src/env/validators.ts lines 76–116

	({ gt, min, lt, max, int }: NumberSchema): ValueValidator =>
	(input) => {
		const num = parseFloat(input ?? '');
		if (isNaN(num)) {
			return {
				ok: false,
				errors: ['type'],
			};
		}
		const errors: Array<string> = [];

		if (gt !== undefined && !(num > gt)) {
			errors.push('gt');
		}
		if (min !== undefined && !(num >= min)) {
			errors.push('min');
		}
		if (lt !== undefined && !(num < lt)) {
			errors.push('lt');
		}
		if (max !== undefined && !(num <= max)) {
			errors.push('max');
		}
		if (int !== undefined) {
			const isInt = Number.isInteger(num);
			if (!(int ? isInt : !isInt)) {
				errors.push('int');
			}
		}

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

Domain

Subdomains

Called By

Frequently Asked Questions

What does numberValidator() do?
numberValidator() is a function in the astro codebase, defined in packages/astro/src/env/validators.ts.
Where is numberValidator() defined?
numberValidator() is defined in packages/astro/src/env/validators.ts at line 76.
What calls numberValidator()?
numberValidator() 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