1 | import isIp from "is-ip";
|
2 | import { Label } from "./parse-domain";
|
3 | import { NO_HOSTNAME } from "./from-url";
|
4 | export declare enum ValidationErrorType {
|
5 | NoHostname = "NO_HOSTNAME",
|
6 | DomainMaxLength = "DOMAIN_MAX_LENGTH",
|
7 | LabelMinLength = "LABEL_MIN_LENGTH",
|
8 | LabelMaxLength = "LABEL_MAX_LENGTH",
|
9 | LabelInvalidCharacter = "LABEL_INVALID_CHARACTER"
|
10 | }
|
11 | export declare type ValidationError = {
|
12 | type: ValidationErrorType;
|
13 | message: string;
|
14 | column: number;
|
15 | };
|
16 | export declare enum SanitizationResultType {
|
17 | ValidIp = "VALID_IP",
|
18 | ValidDomain = "VALID_DOMAIN",
|
19 | Error = "ERROR"
|
20 | }
|
21 | export declare type SanitizationResultValidIp = {
|
22 | type: SanitizationResultType.ValidIp;
|
23 | ip: string;
|
24 | ipVersion: Exclude<ReturnType<typeof isIp.version>, undefined>;
|
25 | };
|
26 | export declare type SanitizationResultValidDomain = {
|
27 | type: SanitizationResultType.ValidDomain;
|
28 | domain: string;
|
29 | labels: Array<Label>;
|
30 | };
|
31 | export declare type SanitizationResultError = {
|
32 | type: SanitizationResultType.Error;
|
33 | errors: Array<ValidationError>;
|
34 | };
|
35 | export declare type SanitizationResult = SanitizationResultValidIp | SanitizationResultValidDomain | SanitizationResultError;
|
36 | export declare const sanitize: (input: string | typeof NO_HOSTNAME) => SanitizationResult;
|