@type Data Types
The @type
item decorator sets the data type associated with an item. The data type affects coercion, validation, and generated type files.
Additional data type options
Section titled “Additional data type options”All types (except enum
) can be used without any arguments, but most take optional arguments that further narrow the type’s behavior.
# @type=stringNO_ARGS=# @type=string(minLength=5, maxLength=10, toUpperCase=true)WITH_ARGS=
Coercion & Validation Process
Section titled “Coercion & Validation Process”Once a raw value is resolved - which could from a static value in an .env
file, a function, or an override passed into the process - the raw value will be coerced and validated based on the type, respecting additional arguments provided to the type.
Consider the following example:
# @type=number(precision=0, max=100)ITEM="123.45"
The internal coercion/validation process would look like —
"123.45"
-> 123.45
-> 123
-> ❌ invalid (greater than max)
Default Behavior
Section titled “Default Behavior”When no @type
is specified and the schema contains a static value, a type will be inferred. Otherwise, the item type will default to string
.
INFERRED_STRING="foo"INFERRED_NUMBER=123INFERRED_BOOLEAN=trueDEFAULTS_TO_STRING_FN=someFn()DEFAULTS_TO_STRING=
Built-in Data types
Section titled “Built-in Data types”These are the built-in data types. In the future, plugins will be able to register additional data types.
string
Section titled “string”Options:
minLength
(number): Minimum length of the stringmaxLength
(number): Maximum length of the stringisLength
(number): Exact length requiredstartsWith
(string): Required starting substringendsWith
(string): Required ending substringmatches
(string|RegExp): Regular expression pattern to matchtoUpperCase
(boolean): Convert to uppercasetoLowerCase
(boolean): Convert to lowercaseallowEmpty
(boolean): Allow empty string (default: false)
# @type=string(minLength=5, maxLength=10, toUpperCase=true)MY_STRING=value
number
Section titled “number”Options:
min
(number): Minimum allowed value (inclusive)max
(number): Maximum allowed value (inclusive)coerceToMinMaxRange
(boolean): Coerce value to be withinmin
/max
rangeisDivisibleBy
(number): Value must be divisible by this numberisInt
(boolean): Value must be an integer (equivalent toprecision=0
)precision
(number): Number of decimal places to keep
# @type=number(min=0, max=100, precision=1)MY_NUMBER=42.5
boolean
Section titled “boolean”The following values will be coerced to a boolean and considered valid:
- True values:
"t"
,"true"
,true
,"yes"
,"on"
,"1"
,1
- False values:
"f"
,"false"
,false
,"no"
,"off"
,"0"
,0
Anything else will be considered invalid.
# @type=booleanMY_BOOL=true
Options:
prependHttps
(boolean): Automatically prepend “https://” if no protocol is specified
# @type=url(prependHttps=true)MY_URL=example.com/foobar
Checks a value is contained in a list of possible values - it must match one exactly.
NOTE - this is the only type that cannot be used without any additional arguments
# @type=enum(development, staging, production)ENV=development
Options:
normalize
(boolean): Convert email to lowercase
# @type=email(normalize=true)MY_EMAIL=User@Example.com
Checks for valid port number. Coerces to a number.
Options:
min
(number): Minimum port number (default: 0)max
(number): Maximum port number (default: 65535)
# @type=port(min=1024, max=9999)MY_PORT=3000
Checks for a valid IP address.
Options:
version
(4|6
): IPv4 or IPv6normalize
(boolean): Convert to lowercase
# @type=ip(version=4, normalize=true)MY_IP=192.168.1.1
semver
Section titled “semver”Checks for a valid semantic version.
# @type=semverMY_VERSION=1.2.3-beta.1
isoDate
Section titled “isoDate”Checks for valid ISO 8601 date strings with optional time and milliseconds.
# @type=isoDateMY_DATE=2024-03-20T15:30:00Z
Checks for valid UUID (versions 1-5 per RFC4122, including NIL
).
# @type=uuidMY_UUID=123e4567-e89b-12d3-a456-426614174000
Checks for valid MD5 hash.
# @type=md5MY_HASH=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
simple-object
Section titled “simple-object”Validates and coerces JSON strings into objects.
# @type=simple-objectMY_OBJECT={"key": "value"}