-
Notifications
You must be signed in to change notification settings - Fork 13
/
decodeBase64.ts
48 lines (45 loc) · 1.34 KB
/
decodeBase64.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { FieldType } from '@terascope/types';
import {
FieldTransformConfig,
ProcessMode,
FunctionDefinitionType,
DataTypeFieldAndChildren,
FunctionDefinitionCategory
} from '../interfaces';
export const decodeBase64Config: FieldTransformConfig = {
name: 'decodeBase64',
type: FunctionDefinitionType.FIELD_TRANSFORM,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.STRING,
description: 'Returns the base64-decoded version of the input string',
examples: [
{
args: {},
config: {
version: 1,
fields: {
testField: {
type: FieldType.String
}
}
},
field: 'testField',
input: 'c29tZSBzdHJpbmc=',
output: 'some string',
}
],
create() {
return (input: unknown) => Buffer.from(input as string, 'base64').toString('utf8');
},
accepts: [FieldType.String],
output_type(inputConfig: DataTypeFieldAndChildren): DataTypeFieldAndChildren {
const { field_config, child_config } = inputConfig;
return {
field_config: {
...field_config,
type: FieldType.String
},
child_config
};
},
};