Creates a preprocessor function that splits a string value by the given separator and trims each resulting element.
Intended for use with array() schemas to parse comma-separated (or similarly delimited) environment variable values.
array()
The delimiter string (e.g. ',', ';', ' ').
','
';'
' '
A preprocessor function suitable for schema.addPreprocessor().
schema.addPreprocessor()
env('ALLOWED_ORIGINS', array(string()).addPreprocessor(splitBy(','), { mutates: false }))// "a, b, c" → ['a', 'b', 'c'] Copy
env('ALLOWED_ORIGINS', array(string()).addPreprocessor(splitBy(','), { mutates: false }))// "a, b, c" → ['a', 'b', 'c']
Creates a preprocessor function that splits a string value by the given separator and trims each resulting element.
Intended for use with
array()schemas to parse comma-separated (or similarly delimited) environment variable values.