UNPKG

4 kBTypeScriptView Raw
1import { AbstractMatch, AbstractMatchConfig } from './abstract-match';
2import type { StripPrefixConfigObj } from '../autolinker';
3/**
4 * @class Autolinker.match.Url
5 * @extends Autolinker.match.AbstractMatch
6 *
7 * Represents a Url match found in an input string which should be Autolinked.
8 *
9 * See this class's superclass ({@link Autolinker.match.Match}) for more details.
10 */
11export declare class UrlMatch extends AbstractMatch {
12 /**
13 * @public
14 * @property {'url'} type
15 *
16 * A string name for the type of match that this class represents. Can be
17 * used in a TypeScript discriminating union to type-narrow from the
18 * `Match` type.
19 */
20 readonly type: 'url';
21 /**
22 * @cfg {String} url (required)
23 *
24 * The url that was matched.
25 */
26 private url;
27 /**
28 * @cfg {"scheme"/"www"/"tld"} urlMatchType (required)
29 *
30 * The type of URL match that this class represents. This helps to determine
31 * if the match was made in the original text with a prefixed scheme (ex:
32 * 'http://www.google.com'), a prefixed 'www' (ex: 'www.google.com'), or
33 * was matched by a known top-level domain (ex: 'google.com').
34 */
35 private readonly urlMatchType;
36 /**
37 * @cfg {Boolean} protocolRelativeMatch (required)
38 *
39 * `true` if the URL is a protocol-relative match. A protocol-relative match
40 * is a URL that starts with '//', and will be either http:// or https://
41 * based on the protocol that the site is loaded under.
42 */
43 private readonly protocolRelativeMatch;
44 /**
45 * @cfg {Object} stripPrefix (required)
46 *
47 * The Object form of {@link Autolinker#cfg-stripPrefix}.
48 */
49 private readonly stripPrefix;
50 /**
51 * @cfg {Boolean} stripTrailingSlash (required)
52 * @inheritdoc Autolinker#cfg-stripTrailingSlash
53 */
54 private readonly stripTrailingSlash;
55 /**
56 * @cfg {Boolean} decodePercentEncoding (required)
57 * @inheritdoc Autolinker#cfg-decodePercentEncoding
58 */
59 private readonly decodePercentEncoding;
60 /**
61 * @private
62 * @property {Boolean} protocolPrepended
63 *
64 * Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the
65 * {@link #url} did not have a protocol)
66 */
67 private protocolPrepended;
68 /**
69 * @method constructor
70 * @param {Object} cfg The configuration properties for the Match
71 * instance, specified in an Object (map).
72 */
73 constructor(cfg: UrlMatchConfig);
74 /**
75 * Returns a string name for the type of match that this class represents.
76 * For the case of UrlMatch, returns 'url'.
77 *
78 * @return {String}
79 */
80 getType(): 'url';
81 /**
82 * Returns a string name for the type of URL match that this class
83 * represents.
84 *
85 * This helps to determine if the match was made in the original text with a
86 * prefixed scheme (ex: 'http://www.google.com'), a prefixed 'www' (ex:
87 * 'www.google.com'), or was matched by a known top-level domain (ex:
88 * 'google.com').
89 *
90 * @return {"scheme"/"www"/"tld"}
91 */
92 getUrlMatchType(): UrlMatchType;
93 /**
94 * Returns the url that was matched, assuming the protocol to be 'http://' if the original
95 * match was missing a protocol.
96 *
97 * @return {String}
98 */
99 getUrl(): string;
100 /**
101 * Returns the anchor href that should be generated for the match.
102 *
103 * @return {String}
104 */
105 getAnchorHref(): string;
106 /**
107 * Returns the anchor text that should be generated for the match.
108 *
109 * @return {String}
110 */
111 getAnchorText(): string;
112}
113export interface UrlMatchConfig extends AbstractMatchConfig {
114 url: string;
115 urlMatchType: UrlMatchType;
116 protocolRelativeMatch: boolean;
117 stripPrefix: Required<StripPrefixConfigObj>;
118 stripTrailingSlash: boolean;
119 decodePercentEncoding: boolean;
120}
121export declare type UrlMatchType = 'scheme' | 'tld' | 'ipV4';