/
isIPv4.ts
47 lines (45 loc) · 1.53 KB
/
isIPv4.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
import { isIPv4 } from '@terascope/utils';
import { FieldType } from '@terascope/types';
import {
FieldValidateConfig, ProcessMode, FunctionDefinitionType,
FunctionDefinitionCategory
} from '../interfaces';
export const isIPv4Config: FieldValidateConfig = {
name: 'isIPv4',
type: FunctionDefinitionType.FIELD_VALIDATION,
process_mode: ProcessMode.INDIVIDUAL_VALUES,
category: FunctionDefinitionCategory.IP,
examples: [
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: '11.0.1.18',
output: '11.0.1.18',
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: '2001:db8:85a3:8d3:1319:8a2e:370:7348',
output: null,
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: '172.394.0.1',
output: null,
},
{
args: {},
config: { version: 1, fields: { testField: { type: FieldType.String } } },
field: 'testField',
input: 'not an IP address',
output: null,
},
],
description: 'Returns the input if it is a valid IPv4 address in dot notation, otherwise returns null',
create() { return isIPv4; },
accepts: [FieldType.String, FieldType.IP],
};