/
isUUID.ts
55 lines (53 loc) · 1.8 KB
/
isUUID.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
import { isUUID } from '@terascope/utils';
import { FieldType } from '@terascope/types';
import {
FieldValidateConfig, ProcessMode, FunctionDefinitionType,
FunctionDefinitionCategory, FunctionDefinitionExample
} from '../interfaces';
const examples: FunctionDefinitionExample<Record<string, unknown>>[] = [
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: '95ecc380-afe9-11e4-9b6c-751b66dd541e',
output: '95ecc380-afe9-11e4-9b6c-751b66dd541e'
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: '123e4567-e89b-82d3-f456-426655440000',
output: '123e4567-e89b-82d3-f456-426655440000'
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: '95ecc380:afe9:11e4:9b6c:751b66dd541e',
output: null
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: '123e4567-e89b-x2d3-0456-426655440000',
output: null
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'randomstring',
output: null
},
];
export const isUUIDConfig: FieldValidateConfig = {
name: 'isUUID',
type: FunctionDefinitionType.FIELD_VALIDATION,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.STRING,
description: 'Returns the input if it is a valid UUID, otherwise returns null.',
examples,
create() { return isUUID; },
accepts: [FieldType.String]
};