Skip to content

Function: createTransformer()

createTransformer(decode, encode)

createTransformer<T>(decode, encode?): TTransformer<T>

Create custom transformer

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
decode(value) => TA function to parse string from CSV cell
encode?(value) => stringA function to format value back to string

Returns

TTransformer<T>

Example

ts
const asMarkdownList = createTransformer(
	(str) => str
		.split('\n')
		.map((line) => line.replace('- ', '').trim())
		.filter((item) => item.length > 0),
);

Defined in

src/transformer/create-transformer.ts:52

createTransformer(decode, encode, decodeSchema)

createTransformer<S, T>(decode, encode, decodeSchema): TTransformer<T, S>

Create a custom transformer

Type Parameters

Type ParameterDefault type
S extends TSchema-
TStaticDecode<S>

Parameters

ParameterTypeDescription
decode(value) => unknownA function to parse string from CSV cell
encode(value) => stringA function to format value back to string
decodeSchemaSA schema to validate decoded value

Returns

TTransformer<T, S>

Example

ts
const asMarkdownList = createTransformer(
	(str) => str
		.split('\n')
		.map((line) => line.replace('- ', '').trim())
		.filter((item) => item.length > 0),
	(items) => items.map(item => `- ${item}`).join('\n')
);

Defined in

src/transformer/create-transformer.ts:72

Released under the MIT License.