Function normalizeOptionValue

  • Normalizes a value for an option based on the option's configuration:

    • Coerce empty strings to undefined.
    • Split string values into arrays for array options and trim whitespace.
    • Parse numbers and booleans.

    Parameters

    • value: unknown

      The value to prepare.

    • Optionalconfig:
          | (
              { type: "string"; customType?: OptionCustomType<"string"> | undefined; choices?: string[] | undefined; string?: boolean | undefined; alias?: MaybeReadonly<string[]> | undefined; description?: string | undefined; required?: boolean | undefined; requires?: MaybeReadonly<...> | undefined; conflicts?: MaybeReadonly<...>...
          )
          | (
              { type: "number"; customType?: "number" | undefined; choices?: string[] | undefined; string?: boolean | undefined; alias?: MaybeReadonly<string[]> | undefined; description?: string | undefined; required?: boolean | undefined; requires?: MaybeReadonly<...> | undefined; conflicts?: MaybeReadonly<...> | undefined; } & ...
          )
          | (
              { type: "boolean"; customType?: "boolean" | undefined; choices?: string[] | undefined; string?: boolean | undefined; alias?: MaybeReadonly<string[]> | undefined; description?: string | undefined; required?: boolean | undefined; requires?: MaybeReadonly<...> | undefined; conflicts?: MaybeReadonly<...> | undefined; } ...
          )
          | (
              { type: "secret"; customType?: OptionCustomType<"secret"> | undefined; choices?: string[] | undefined; string?: boolean | undefined; alias?: MaybeReadonly<string[]> | undefined; description?: string | undefined; required?: boolean | undefined; requires?: MaybeReadonly<...> | undefined; conflicts?: MaybeReadonly<...>...
          )
          | (
              { type: "array"; customType?: "array" | undefined; choices?: string[] | undefined; string?: boolean | undefined; alias?: MaybeReadonly<string[]> | undefined; description?: string | undefined; required?: boolean | undefined; requires?: MaybeReadonly<...> | undefined; conflicts?: MaybeReadonly<...> | undefined; } & ({...
          )

      The option configuration for the value.

    Returns undefined | OptionPrimitiveType<(keyof OptionPrimitiveTypeMap)>

    • The prepared value.