/
endsWith.ts
59 lines (57 loc) · 1.86 KB
/
endsWith.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
import { FieldType } from '@terascope/types';
import { endsWithFP } from '@terascope/utils';
import {
FieldValidateConfig, ProcessMode, FunctionDefinitionType,
FunctionDefinitionCategory
} from '../interfaces';
export interface EndsWithArgs {
value: string
}
export const endsWithConfig: FieldValidateConfig<EndsWithArgs> = {
name: 'endsWith',
type: FunctionDefinitionType.FIELD_VALIDATION,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.STRING,
examples: [
{
args: { value: 'e' },
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'apple',
output: 'apple'
},
{
args: { value: 'a' },
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'orange',
output: null
},
{
args: { value: 'so' },
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'some word',
output: null
},
{
args: { value: 'word' },
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'other word',
output: 'other word'
},
],
description: 'Returns the input if it ends with the args value string, otherwise returns null. This is case-sensitive.',
create({ args: { value } }) {
return endsWithFP(value);
},
argument_schema: {
value: {
type: FieldType.String,
description: 'The value compared to the end of the input string '
}
},
accepts: [FieldType.String],
required_arguments: ['value'],
};