Skip to main content

@sveltejs/kit/env

import { function defineEnvVars<T extends Record<string, EnvVarConfig<any>>>(variables: T): DefinedEnvVars<T>

Utility for defining environment variables, which are made available via $app/env/public and $app/env/private.

@example
import { defineEnvVars } from '@sveltejs/kit/env';
import * as v from 'valibot';

export const variables = defineEnvVars({
	API_URL: {
		schema: v.pipe(v.string(), v.url())
	},
	PORT: {
		schema: (value) => {
			if (value === undefined) return 3000;
			const port = Number(value);
			if (!Number.isInteger(port)) throw new Error('PORT must be an integer');
			return port;
		}
	}
});
defineEnvVars
} from '@sveltejs/kit/env';

defineEnvVars

Utility for defining environment variables, which are made available via $app/env/public and $app/env/private.

import { function defineEnvVars<T extends Record<string, EnvVarConfig<any>>>(variables: T): DefinedEnvVars<T>

Utility for defining environment variables, which are made available via $app/env/public and $app/env/private.

@example
import { defineEnvVars } from '@sveltejs/kit/env';
import * as v from 'valibot';

export const variables = defineEnvVars({
	API_URL: {
		schema: v.pipe(v.string(), v.url())
	},
	PORT: {
		schema: (value) => {
			if (value === undefined) return 3000;
			const port = Number(value);
			if (!Number.isInteger(port)) throw new Error('PORT must be an integer');
			return port;
		}
	}
});
defineEnvVars
} from '@sveltejs/kit/env';
import * as import vv from 'valibot'; export const
const variables: DefinedEnvVars<{
    API_URL: {
        schema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
    };
    PORT: {
        schema: (value: string | undefined) => number;
    };
}>
variables
=
defineEnvVars<{
    API_URL: {
        schema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
    };
    PORT: {
        schema: (value: string | undefined) => number;
    };
}>(variables: {
    API_URL: {
        schema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
    };
    PORT: {
        schema: (value: string | undefined) => number;
    };
}): DefinedEnvVars<{
    API_URL: {
        schema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
    };
    PORT: {
        schema: (value: string | undefined) => number;
    };
}>

Utility for defining environment variables, which are made available via $app/env/public and $app/env/private.

@example
import { defineEnvVars } from '@sveltejs/kit/env';
import * as v from 'valibot';

export const variables = defineEnvVars({
	API_URL: {
		schema: v.pipe(v.string(), v.url())
	},
	PORT: {
		schema: (value) => {
			if (value === undefined) return 3000;
			const port = Number(value);
			if (!Number.isInteger(port)) throw new Error('PORT must be an integer');
			return port;
		}
	}
});
defineEnvVars
({
type API_URL: {
    schema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
}
API_URL
: {
schema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>schema: import vv.
pipe<v.StringSchema<undefined>, v.UrlAction<string, undefined>>(schema: v.StringSchema<undefined>, item1: v.UrlAction<string, undefined> | v.PipeAction<string, string, v.UrlIssue<string>>): v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]> (+20 overloads)
export pipe

Adds a pipeline to a schema, that can validate and transform its input.

@param
schema The root schema.
@param
item1 The first pipe item.
@returns
A schema with a pipeline.
pipe
(import vv.
function string(): v.StringSchema<undefined> (+1 overload)
export string

Creates a string schema.

@returns
A string schema.
string
(), import vv.
url<string>(): v.UrlAction<string, undefined> (+1 overload)
export url

Creates an URL validation action.

Hint: The value is passed to the URL constructor to check if it is valid. This check is not perfect. For example, values like "abc:1234" are accepted.

@returns
An URL action.
url
())
},
type PORT: {
    schema: (value: string | undefined) => number;
}
PORT
: {
schema: (value: string | undefined) => numberschema: (value: string | undefinedvalue) => { if (value: string | undefinedvalue === var undefinedundefined) return 3000; const const port: numberport =
var Number: NumberConstructor
(value?: any) => number

An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

Number
(value: stringvalue);
if (!var Number: NumberConstructor

An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

Number
.NumberConstructor.isInteger(number: unknown): boolean

Returns true if the value passed is an integer, false otherwise.

@param
number A numeric value.
isInteger
(const port: numberport)) throw new
var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error
('PORT must be an integer');
return const port: numberport; } } });
function defineEnvVars<
	T extends Record<string, EnvVarConfig<any>>
>(variables: T): DefinedEnvVars<T>;

Edit this page on GitHub llms.txt