Function: createTransformer()
createTransformer(decode, encode)
createTransformer<
T
>(decode
,encode
?):TTransformer
<T
>
Create custom transformer
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
decode | (value ) => T | A function to parse string from CSV cell |
encode ? | (value ) => string | A 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 Parameter | Default type |
---|---|
S extends TSchema | - |
T | StaticDecode <S > |
Parameters
Parameter | Type | Description |
---|---|---|
decode | (value ) => unknown | A function to parse string from CSV cell |
encode | (value ) => string | A function to format value back to string |
decodeSchema | S | A 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')
);