Skip to content

Function: asArray()

asArray<T, S>(itemTransformer, separator, options?): TTransformer<Static<TDecodeType<S>, unknown[] & []>[], TArray<S>>

Create an array transformer. Split string with separator and apply itemTransformer to each item.

Type Parameters

Type Parameter
T
S extends TSchema

Parameters

ParameterTypeDefault valueDescription
itemTransformerTTransformer<T, S>undefinedTransformer for each item
separatorstring','A string that separate each item
options?ArrayOptionsundefinedValidation options (see ArrayOptions)

Returns

TTransformer<Static<TDecodeType<S>, unknown[] & []>[], TArray<S>>

Example

ts
// Example: "food, transport, rent" -> ['food', 'transport', 'rent']
Column('categories', asArray(asString()));

Defined in

src/transformer/as-array.ts:17

Released under the MIT License.