1 | import { ipVersion } from "is-ip";
|
2 | import { Label } from "./parse-domain.js";
|
3 | import { NO_HOSTNAME } from "./from-url.js";
|
4 | export declare enum Validation {
|
5 | |
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | Lax = "LAX",
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | Strict = "STRICT"
|
22 | }
|
23 | export declare enum ValidationErrorType {
|
24 | NoHostname = "NO_HOSTNAME",
|
25 | DomainMaxLength = "DOMAIN_MAX_LENGTH",
|
26 | LabelMinLength = "LABEL_MIN_LENGTH",
|
27 | LabelMaxLength = "LABEL_MAX_LENGTH",
|
28 | LabelInvalidCharacter = "LABEL_INVALID_CHARACTER",
|
29 | LastLabelInvalid = "LAST_LABEL_INVALID"
|
30 | }
|
31 | export type ValidationError = {
|
32 | type: ValidationErrorType;
|
33 | message: string;
|
34 | column: number;
|
35 | };
|
36 | export declare enum SanitizationResultType {
|
37 | ValidIp = "VALID_IP",
|
38 | ValidDomain = "VALID_DOMAIN",
|
39 | Error = "ERROR"
|
40 | }
|
41 | export type SanitizationResultValidIp = {
|
42 | type: SanitizationResultType.ValidIp;
|
43 | ip: string;
|
44 | ipVersion: Exclude<ReturnType<typeof ipVersion>, undefined>;
|
45 | };
|
46 | export type SanitizationResultValidDomain = {
|
47 | type: SanitizationResultType.ValidDomain;
|
48 | domain: string;
|
49 | labels: Array<Label>;
|
50 | };
|
51 | export type SanitizationResultError = {
|
52 | type: SanitizationResultType.Error;
|
53 | errors: Array<ValidationError>;
|
54 | };
|
55 | export type SanitizationResult = SanitizationResultValidIp | SanitizationResultValidDomain | SanitizationResultError;
|
56 | export declare const sanitize: (input: string | typeof NO_HOSTNAME, options?: {
|
57 | validation?: Validation;
|
58 | }) => SanitizationResult;
|