2022-11-16 04:15:53 +00:00
|
|
|
import { REP_IPV4 } from '../consts/REG_EXP_PATTERNS';
|
|
|
|
|
2023-04-04 03:25:23 +00:00
|
|
|
import testNotBlank from './testNotBlank';
|
|
|
|
|
2022-11-16 04:15:53 +00:00
|
|
|
const buildIPAddressTestBatch: BuildInputTestBatchFunction = (
|
|
|
|
inputName,
|
|
|
|
onSuccess,
|
2023-03-04 00:28:48 +00:00
|
|
|
{ isRequired, onFinishBatch, ...defaults } = {},
|
2022-11-16 04:15:53 +00:00
|
|
|
onIPv4TestFailure,
|
|
|
|
) => ({
|
2022-11-25 04:56:46 +00:00
|
|
|
defaults: { ...defaults, onSuccess },
|
2023-03-04 00:28:48 +00:00
|
|
|
isRequired,
|
2022-11-25 04:56:46 +00:00
|
|
|
onFinishBatch,
|
2022-11-16 04:15:53 +00:00
|
|
|
tests: [
|
2023-04-04 03:25:23 +00:00
|
|
|
{
|
|
|
|
test: testNotBlank,
|
|
|
|
},
|
2022-11-16 04:15:53 +00:00
|
|
|
{
|
|
|
|
onFailure: (...args) => {
|
|
|
|
onIPv4TestFailure(
|
2023-04-04 03:25:23 +00:00
|
|
|
<>{inputName} should be a valid IPv4 address.</>,
|
2022-11-16 04:15:53 +00:00
|
|
|
...args,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
test: ({ value }) => REP_IPV4.test(value as string),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
export default buildIPAddressTestBatch;
|