/
toBoolean.ts
73 lines (71 loc) · 1.91 KB
/
toBoolean.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { toBoolean } from '@terascope/utils';
import { FieldType } from '@terascope/types';
import {
FieldTransformConfig,
ProcessMode,
FunctionDefinitionType,
DataTypeFieldAndChildren,
FunctionDefinitionCategory
} from '../interfaces';
export const toBooleanConfig: FieldTransformConfig = {
name: 'toBoolean',
type: FunctionDefinitionType.FIELD_TRANSFORM,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.BOOLEAN,
description: 'Converts the input into a boolean and returns the boolean value',
examples: [
{
args: {},
config: {
version: 1,
fields: { testField: { type: FieldType.String } }
},
field: 'testField',
input: 'TRUE',
output: true
},
{
args: {},
config: {
version: 1,
fields: { testField: { type: FieldType.Number } }
},
field: 'testField',
input: 1,
output: true
},
{
args: {},
config: {
version: 1,
fields: { testField: { type: FieldType.Number } }
},
field: 'testField',
input: 0,
output: false
},
{
args: {},
config: {
version: 1,
fields: { testField: { type: FieldType.Any } }
},
field: 'testField',
input: null,
output: null
}
],
create() {
return toBoolean;
},
accepts: [],
output_type(inputConfig: DataTypeFieldAndChildren): DataTypeFieldAndChildren {
const { field_config } = inputConfig;
return {
field_config: {
...field_config,
type: FieldType.Boolean
},
};
}
};