Libraries
    Preparing search index...

    Function splitBy

    • 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.

      Type Parameters

      • T = string

      Parameters

      • separator: string

        The delimiter string (e.g. ',', ';', ' ').

      Returns (value: T[]) => T[]

      A preprocessor function suitable for schema.addPreprocessor().

      env('ALLOWED_ORIGINS', array(string()).addPreprocessor(splitBy(','), { mutates: false }))
      // "a, b, c" → ['a', 'b', 'c']