cizgile 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/uri.d.mts CHANGED
@@ -1,156 +1,281 @@
1
1
  //#region src/uri/charset.d.ts
2
+ /** The named keep-sets `percentEncode` understands: the RFC 3986 productions and the WHATWG percent-encode sets. */
2
3
  type EncodeSetName = "unreserved" | "pchar" | "segment-nz-nc" | "path" | "query" | "fragment" | "userinfo" | "whatwg-c0-control" | "whatwg-fragment" | "whatwg-query" | "whatwg-special-query" | "whatwg-path" | "whatwg-userinfo" | "whatwg-component" | "form";
4
+ /** A named keep-set or a predicate over code points that returns true for characters to leave unencoded. */
3
5
  type EncodeSet = EncodeSetName | ((codePoint: number) => boolean);
6
+ /** RFC 3986 `ALPHA`. */
4
7
  export declare function isAlpha(cp: number): boolean;
8
+ /** RFC 3986 `DIGIT`. */
5
9
  export declare function isDigit(cp: number): boolean;
10
+ /** RFC 3986 `HEXDIG`, either case. */
6
11
  export declare function isHexDigit(cp: number): boolean;
12
+ /** Whether `text` is a valid RFC 3986 `scheme`: a letter followed by letters, digits, `+`, `-` or `.`. */
7
13
  export declare function isScheme(text: string): boolean;
14
+ /** RFC 3986 section 2.3 `unreserved`: letters, digits, `- . _ ~`. */
8
15
  export declare function isUnreserved(cp: number): boolean;
16
+ /** RFC 3986 section 2.2 `gen-delims`: `: / ? # [ ] @`. */
9
17
  export declare function isGenDelim(cp: number): boolean;
18
+ /** RFC 3986 section 2.2 `sub-delims`: `! $ & ' ( ) * + , ; =`. */
10
19
  export declare function isSubDelim(cp: number): boolean;
20
+ /** RFC 3986 section 2.2 `reserved`: `gen-delims` or `sub-delims`. */
11
21
  export declare function isReserved(cp: number): boolean;
22
+ /** RFC 3986 section 3.3 `pchar` less `pct-encoded`: `unreserved`, `sub-delims`, `:` or `@`. */
12
23
  export declare function isPchar(cp: number): boolean;
24
+ /** RFC 3986 section 3.3 `segment-nz-nc` character: `pchar` without the colon. */
13
25
  export declare function isSegmentNzNc(cp: number): boolean;
26
+ /** A character allowed unencoded in a `query` or `fragment`: `pchar`, `/` or `?`. */
14
27
  export declare function isQueryChar(cp: number): boolean;
28
+ /** The predicate behind a named keep-set, or the predicate itself. */
15
29
  export declare function resolveEncodeSet(set: EncodeSet): (codePoint: number) => boolean;
16
30
  //#endregion
17
31
  //#region src/uri/normalize.d.ts
32
+ /** Options for `normalizeUri`. */
18
33
  interface NormalizeUriOptions {
34
+ /** Scheme to default port, merged over `DEFAULT_PORTS`. */
19
35
  readonly defaultPorts?: Readonly<Record<string, number>>;
36
+ /** RFC 3986 section 6.2.3: drop default ports and turn an empty path into `/`; `true` by default. */
20
37
  readonly schemeBased?: boolean;
38
+ /** Redacts credentials, for logs; `"keep"` by default. */
21
39
  readonly userinfo?: "keep" | "strip-password" | "strip";
22
40
  }
41
+ /** Default ports of the common schemes, used by `normalizeUri` and `equivalentUris`. */
23
42
  export declare const DEFAULT_PORTS: Readonly<Record<string, number>>;
43
+ /** The parts of an RFC 3986 `authority`. */
24
44
  interface AuthorityComponents {
45
+ /** Without the trailing `@`. */
25
46
  userinfo?: string;
47
+ /** As written, brackets included for IP literals. */
26
48
  host: string;
49
+ /** Digits only, without the colon; `""` when the colon was present but empty. */
27
50
  port?: string;
28
51
  }
52
+ /** Splits an authority into userinfo, host and port. */
29
53
  export declare function parseAuthority(authority: string): AuthorityComponents;
54
+ /** Recomposes an authority from its parts. */
30
55
  export declare function serializeAuthority(components: AuthorityComponents): string;
56
+ /** RFC 3986 section 6.2 syntax-based and scheme-based normalisation: case, percent-encoding, dot segments, default ports, empty path. */
31
57
  export declare function normalizeUri(input: string, options?: NormalizeUriOptions): string;
32
58
  //#endregion
33
59
  //#region src/uri/compare.d.ts
60
+ /** The RFC 3986 section 6.2 comparison ladder: string, syntax-based or scheme-based normalisation. */
34
61
  type EquivalenceLevel = "simple" | "syntax" | "scheme";
62
+ /** Options for `equivalentUris`. */
35
63
  interface EquivalentUrisOptions {
64
+ /** How much normalisation to apply before comparing; `"scheme"` by default. */
36
65
  readonly level?: EquivalenceLevel;
66
+ /** Resolves both references against this base first. */
37
67
  readonly base?: string;
68
+ /** Compares without the fragments. */
38
69
  readonly ignoreFragment?: boolean;
70
+ /** Scheme to default port, merged over `DEFAULT_PORTS`. */
39
71
  readonly defaultPorts?: NormalizeUriOptions["defaultPorts"];
40
72
  }
73
+ /** Whether two URIs identify the same resource under the chosen normalisation level. IRIs are never mapped to URIs (RFC 3987 section 5.3.1). */
41
74
  export declare function equivalentUris(a: string, b: string, options?: EquivalentUrisOptions): boolean;
75
+ /** Options for `isSameDocumentReference`. */
42
76
  interface SameDocumentOptions {
77
+ /** Normalises both sides before comparing. */
43
78
  readonly normalize?: boolean;
44
79
  }
80
+ /** RFC 3986 section 4.4: whether `reference` resolved against `base` differs from it only in the fragment. */
45
81
  export declare function isSameDocumentReference(base: string, reference: string, options?: SameDocumentOptions): boolean;
46
82
  //#endregion
47
83
  //#region src/uri/encode.d.ts
84
+ /** Options for `encodePathSegment`. */
48
85
  interface EncodePathSegmentOptions {
86
+ /** Also encodes `:`, for the first segment of a relative reference (`segment-nz-nc`). */
49
87
  readonly noColon?: boolean;
50
88
  }
89
+ /** Encodes one path segment so that `/`, `?` and `#` inside it cannot be mistaken for delimiters. */
51
90
  export declare function encodePathSegment(segment: string, options?: EncodePathSegmentOptions): string;
91
+ /** Options for `encodePath`. */
52
92
  interface EncodePathOptions {
93
+ /** Encodes the colon in the first segment so the path cannot be read as a scheme. */
53
94
  readonly relative?: boolean;
54
95
  }
96
+ /** Encodes each segment of `path`, keeping the `/` separators. */
55
97
  export declare function encodePath(path: string, options?: EncodePathOptions): string;
98
+ /** Encodes `query` with the RFC 3986 `query` set, keeping `/`, `?`, `=` and `&`. */
56
99
  export declare function encodeQuery(query: string): string;
100
+ /** Encodes `fragment` with the RFC 3986 `fragment` set. */
57
101
  export declare function encodeFragment(fragment: string): string;
102
+ /** `application/x-www-form-urlencoded` encoding of one value: spaces become `+`, `*-._` and alphanumerics stay. */
58
103
  export declare function encodeForm(value: string): string;
59
104
  //#endregion
60
105
  //#region src/uri/extract.d.ts
106
+ /** RFC 3986 Appendix C: recovers a URI from text that wraps it in `<>`, quotes or brackets, prefixes it with `URL:`, breaks it across lines or ends it with punctuation. Markdown links and `href`/`src` attributes yield their URL. */
61
107
  export declare function extractUri(text: string): string;
62
108
  //#endregion
63
109
  //#region src/uri/host.d.ts
110
+ /** The three RFC 3986 section 3.2.2 host forms. */
64
111
  type HostKind = "ip-literal" | "ipv4" | "reg-name";
112
+ /** The result of `parseHost`. */
65
113
  interface ParsedHost {
114
+ /** Which host production matched. */
66
115
  readonly kind: HostKind;
116
+ /** The address without brackets, or the registered name as written. */
67
117
  readonly value: string;
68
118
  }
119
+ /** RFC 3986 `IPv4address`: four decimal octets, no leading zeros; `0x7f.0.0.1` is a registered name, not an address. */
69
120
  export declare function isIPv4Address(text: string): boolean;
121
+ /** RFC 3986 `IPv6address`, all nine ABNF alternatives including the embedded IPv4 form. */
70
122
  export declare function isIPv6Address(text: string): boolean;
123
+ /** RFC 3986 `IPvFuture`: `v` + hex + `.` + unreserved or sub-delims. */
71
124
  export declare function isIPvFuture(text: string): boolean;
125
+ /** RFC 3986 `IP-literal`: an IPv6 address or IPvFuture in square brackets. */
72
126
  export declare function isIPLiteral(text: string): boolean;
127
+ /** RFC 3986 `reg-name`: unreserved, percent-encoded and sub-delims characters, possibly empty. */
73
128
  export declare function isRegName(text: string): boolean;
129
+ /** Classifies `text` as an IP literal, IPv4 address or registered name, or returns `undefined`. */
74
130
  export declare function parseHost(text: string): ParsedHost | undefined;
131
+ /** Whether `text` is a valid RFC 3986 `host`. */
75
132
  export declare function isHost(text: string): boolean;
76
133
  //#endregion
77
134
  //#region src/uri/iri.d.ts
135
+ /** RFC 3987 `ucschar`: the non-ASCII code points an IRI may contain unencoded. */
78
136
  export declare function isUcschar(cp: number): boolean;
137
+ /** RFC 3987 `iprivate`: private-use code points, allowed only in the query. */
79
138
  export declare function isIprivate(cp: number): boolean;
139
+ /** Whether `cp` is a bidirectional formatting character (RFC 3987 section 4.1 forbids them). */
80
140
  export declare function isBidiControl(cp: number): boolean;
141
+ /** Whether `input` contains any bidirectional formatting character. */
81
142
  export declare function hasBidiControls(input: string): boolean;
143
+ /** RFC 3987 `iunreserved`: `unreserved` or `ucschar`. */
82
144
  export declare function isIunreserved(cp: number): boolean;
145
+ /** RFC 3987 `ipchar` less `pct-encoded`. */
83
146
  export declare function isIpchar(cp: number): boolean;
147
+ /** Options for `iriToUri`. */
84
148
  interface IriToUriOptions {
149
+ /** What to do with bidirectional formatting characters: throw, or strip them; by default they are percent-encoded like any other character. */
85
150
  readonly bidi?: "throw" | "strip";
151
+ /** Normalises to NFC first; off by default because RFC 3987 section 3.1 says not to alter characters. */
86
152
  readonly nfc?: boolean;
153
+ /** Rejects characters no IRI may contain instead of encoding them. */
87
154
  readonly strict?: boolean;
155
+ /** How to convert a non-ASCII host: percent-encode it (default) or apply `domainToAscii`. */
88
156
  readonly host?: "percent" | "punycode";
89
157
  }
158
+ /** RFC 3987 section 3.1: percent-encodes the non-ASCII characters of an IRI, component by component, without altering them. */
90
159
  export declare function iriToUri(iri: string, options?: IriToUriOptions): string;
160
+ /** RFC 3987 section 3.2: decodes the percent-encoded sequences a URI may show as characters, and only those, per component. */
91
161
  export declare function uriToIri(uri: string): string;
92
162
  //#endregion
93
163
  //#region src/uri/parse.d.ts
164
+ /** The five RFC 3986 components. An absent component is `undefined`; an empty one is `""`, and the two serialise differently. */
94
165
  interface UriComponents {
166
+ /** Without the trailing colon. */
95
167
  scheme?: string;
168
+ /** Without the leading `//`; split it with `parseAuthority`. */
96
169
  authority?: string;
170
+ /** Always present, possibly empty. */
97
171
  path: string;
172
+ /** Without the leading `?`. */
98
173
  query?: string;
174
+ /** Without the leading `#`. */
99
175
  fragment?: string;
100
176
  }
177
+ /** Splits a URI reference into its components with the RFC 3986 Appendix B regular expression; never throws. */
101
178
  export declare function parseUri(input: string): UriComponents;
179
+ /** Recomposes components per RFC 3986 section 5.3, inserting `/.` or `./` where the grammar requires it. */
102
180
  export declare function serializeUri(components: UriComponents): string;
103
181
  //#endregion
104
182
  //#region src/uri/path.d.ts
183
+ /** RFC 3986 section 5.2.4, the two-buffer algorithm as written: resolves `.` and `..` segments. */
105
184
  export declare function removeDotSegments(path: string): string;
185
+ /** Options for `normalizePath`. */
106
186
  interface NormalizePathOptions {
187
+ /** What to do with a trailing slash; `"keep"` by default. */
107
188
  readonly trailingSlash?: "keep" | "add" | "remove";
108
189
  }
190
+ /** Removes dot segments and normalises percent-encoding in a path, relative paths included. */
109
191
  export declare function normalizePath(path: string, options?: NormalizePathOptions): string;
110
192
  //#endregion
111
193
  //#region src/uri/percent.d.ts
194
+ /** Percent-encodes `input` as UTF-8 with uppercase hex, leaving the characters `keep` names untouched; `"form"` also turns spaces into `+`. */
112
195
  export declare function percentEncode(input: string, keep?: EncodeSet): string;
196
+ /** Options for `percentDecode`. */
113
197
  interface PercentDecodeOptions {
198
+ /** Decodes `+` as a space, as `application/x-www-form-urlencoded` does. */
114
199
  readonly plusAsSpace?: boolean;
115
200
  }
201
+ /** Decodes every `%XX` sequence as UTF-8; malformed bytes become U+FFFD and lone `%` is kept. */
116
202
  export declare function percentDecode(input: string, options?: PercentDecodeOptions): string;
203
+ /** RFC 3986 section 6.2.2.2: decodes percent-encoded `unreserved` characters and uppercases the hex of the rest. */
117
204
  export declare function normalizePercentEncoding(input: string): string;
118
205
  //#endregion
119
206
  //#region src/uri/punycode.d.ts
207
+ /** RFC 3492 Punycode encoding of one label, without the `xn--` prefix. */
120
208
  export declare function punycodeEncode(input: string): string;
209
+ /**
210
+ * RFC 3492 Punycode decoding of one label, without the `xn--` prefix.
211
+ * @throws {RangeError} on malformed input.
212
+ */
121
213
  export declare function punycodeDecode(input: string): string;
214
+ /**
215
+ * Converts a domain to its A-label form: maps and lowercases each label the way UTS #46 does, punycodes the non-ASCII ones, and validates lengths, hyphens and existing `xn--` labels. IP literals pass through.
216
+ * @throws {RangeError} when a label or the domain is not valid.
217
+ */
122
218
  export declare function domainToAscii(host: string): string;
219
+ /**
220
+ * Converts the `xn--` labels of a domain back to Unicode and lowercases the rest.
221
+ * @throws {RangeError} when an `xn--` label does not decode to a valid U-label.
222
+ */
123
223
  export declare function domainToUnicode(host: string): string;
124
224
  //#endregion
125
225
  //#region src/uri/relativize.d.ts
226
+ /** The shortest relative reference that resolves against `base` to `target`; the target itself when they share nothing. */
126
227
  export declare function relativize(base: string, target: string): string;
127
228
  //#endregion
128
229
  //#region src/uri/resolve.d.ts
230
+ /** Options for `resolveUri`. */
129
231
  interface ResolveUriOptions {
232
+ /** Strict parsing (RFC 3986 section 5.2.2): `http:g` against an `http:` base stays `http:g`; `true` by default. */
130
233
  readonly strict?: boolean;
234
+ /** Accepts a base without a scheme instead of throwing. */
131
235
  readonly allowRelativeBase?: boolean;
132
236
  }
237
+ /** RFC 3986 section 5.2.3: merges a relative path reference with the base path. */
133
238
  export declare function mergePaths(base: UriComponents, referencePath: string): string;
239
+ /**
240
+ * RFC 3986 section 5.2 reference resolution; every section 5.4 example passes.
241
+ * @throws {TypeError} when `base` is not an absolute URI, unless `allowRelativeBase` is set.
242
+ */
134
243
  export declare function resolveUri(base: string, reference: string, options?: ResolveUriOptions): string;
135
244
  //#endregion
136
245
  //#region src/uri/validate.d.ts
246
+ /** The RFC 3986 section 3.3 path productions. */
137
247
  type PathForm = "empty" | "absolute" | "abempty" | "rootless" | "noscheme";
248
+ /** The result of `classifyReference`. */
138
249
  interface ReferenceClassification {
250
+ /** Whether the reference carries a scheme. */
139
251
  readonly kind: "uri" | "relative";
252
+ /** Whether it is an `absolute-URI`: a scheme and no fragment. */
140
253
  readonly absolute: boolean;
254
+ /** Which path production matched. */
141
255
  readonly path: PathForm;
256
+ /** The parsed components. */
142
257
  readonly components: UriComponents;
143
258
  }
259
+ /** Options for `classifyReference`. */
144
260
  interface ValidateOptions {
261
+ /** Validates against the RFC 3987 IRI grammar instead of the URI grammar. */
145
262
  readonly iri?: boolean;
146
263
  }
264
+ /** Which RFC 3986 path production `path` matches. */
147
265
  export declare function pathForm(path: string, components?: UriComponents): PathForm;
266
+ /** Validates `input` against the RFC 3986 (or 3987) grammar and reports its kind, or returns `undefined` when it does not parse. */
148
267
  export declare function classifyReference(input: string, options?: ValidateOptions): ReferenceClassification | undefined;
268
+ /** Whether `input` is a valid RFC 3986 `URI-reference`. */
149
269
  export declare function isUriReference(input: string): boolean;
270
+ /** Whether `input` is a valid RFC 3986 `URI`: it has a scheme. */
150
271
  export declare function isUri(input: string): boolean;
272
+ /** Whether `input` is a valid RFC 3986 `absolute-URI`: a scheme and no fragment. */
151
273
  export declare function isAbsoluteUri(input: string): boolean;
274
+ /** Whether `input` is a valid RFC 3986 `relative-ref`: no scheme. */
152
275
  export declare function isRelativeReference(input: string): boolean;
276
+ /** Whether `input` is a valid RFC 3987 `IRI-reference`. */
153
277
  export declare function isIriReference(input: string): boolean;
278
+ /** Whether `input` is a valid RFC 3987 `IRI`. */
154
279
  export declare function isIri(input: string): boolean;
155
280
  //#endregion
156
281
  export type { AuthorityComponents, EncodePathOptions, EncodePathSegmentOptions, EncodeSet, EncodeSetName, EquivalenceLevel, EquivalentUrisOptions, HostKind, IriToUriOptions, NormalizePathOptions, NormalizeUriOptions, ParsedHost, PathForm, PercentDecodeOptions, ReferenceClassification, ResolveUriOptions, SameDocumentOptions, UriComponents, ValidateOptions };