/
contains.ts
53 lines (51 loc) · 1.7 KB
/
contains.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
import { containsFP } from '@terascope/utils';
import { FieldType } from '@terascope/types';
import {
FieldValidateConfig, ProcessMode, FunctionDefinitionType,
FunctionDefinitionCategory
} from '../interfaces';
export interface ContainsArgs {
readonly value: string;
}
export const containsConfig: FieldValidateConfig<ContainsArgs> = {
name: 'contains',
type: FunctionDefinitionType.FIELD_VALIDATION,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.STRING,
description: 'Returns the input string if it contains the args substring value, otherwise returns null. This operations is case-sensitive',
examples: [
{
args: { value: 'ample' },
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'example',
output: 'example'
},
{
args: { value: 'example' },
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'example',
output: 'example'
},
{
args: { value: 'test' },
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'example',
output: null
},
],
create({ args: { value } }) {
return containsFP(value);
},
accepts: [FieldType.String],
argument_schema: {
value: {
type: FieldType.String,
array: false,
description: 'A string that must partially or completely match'
}
},
required_arguments: ['value']
};