UNPKG

1.58 kBTypeScriptView Raw
1import type { Nullable } from '../utils';
2/**
3 * Answers "does this real domain match the domain in a cookie?". The `domain` is the "current" domain name and the
4 * `cookieDomain` is the "cookie" domain name. Matches according to {@link https://www.rfc-editor.org/rfc/rfc6265.html#section-5.1.3 | RFC6265 - Section 5.1.3},
5 * but it helps to think of it as a "suffix match".
6 *
7 * @remarks
8 * ### 5.1.3. Domain Matching
9 *
10 * A string domain-matches a given domain string if at least one of the
11 * following conditions hold:
12 *
13 * - The domain string and the string are identical. (Note that both
14 * the domain string and the string will have been canonicalized to
15 * lower case at this point.)
16 *
17 * - All of the following conditions hold:
18 *
19 * - The domain string is a suffix of the string.
20 *
21 * - The last character of the string that is not included in the
22 * domain string is a %x2E (".") character.
23 *
24 * - The string is a host name (i.e., not an IP address).
25 *
26 * @example
27 * ```
28 * domainMatch('example.com', 'example.com') === true
29 * domainMatch('eXaMpLe.cOm', 'ExAmPlE.CoM') === true
30 * domainMatch('no.ca', 'yes.ca') === false
31 * ```
32 *
33 * @param domain - The domain string to test
34 * @param cookieDomain - The cookie domain string to match against
35 * @param canonicalize - The canonicalize parameter toggles whether the domain parameters get normalized with canonicalDomain or not
36 * @public
37 */
38export declare function domainMatch(domain?: Nullable<string>, cookieDomain?: Nullable<string>, canonicalize?: boolean): boolean | undefined;