UNPKG

1.36 kBTypeScriptView Raw
1import type { Nullable } from '../utils';
2/**
3 * Transforms a domain name into a canonical domain name. The canonical domain name is a domain name
4 * that has been trimmed, lowercased, stripped of leading dot, and optionally punycode-encoded
5 * ({@link https://www.rfc-editor.org/rfc/rfc6265.html#section-5.1.2 | Section 5.1.2 of RFC 6265}). For
6 * the most part, this function is idempotent (calling the function with the output from a previous call
7 * returns the same output).
8 *
9 * @remarks
10 * A canonicalized host name is the string generated by the following
11 * algorithm:
12 *
13 * 1. Convert the host name to a sequence of individual domain name
14 * labels.
15 *
16 * 2. Convert each label that is not a Non-Reserved LDH (NR-LDH) label,
17 * to an A-label (see Section 2.3.2.1 of [RFC5890] for the former
18 * and latter), or to a "punycode label" (a label resulting from the
19 * "ToASCII" conversion in Section 4 of [RFC3490]), as appropriate
20 * (see Section 6.3 of this specification).
21 *
22 * 3. Concatenate the resulting labels, separated by a %x2E (".")
23 * character.
24 *
25 * @example
26 * ```
27 * canonicalDomain('.EXAMPLE.com') === 'example.com'
28 * ```
29 *
30 * @param domainName - the domain name to generate the canonical domain from
31 * @public
32 */
33export declare function canonicalDomain(domainName: Nullable<string>): string | undefined;