Skip to content

Commit 293ae08

Browse files
committed
docs(js): initial doc for std URL
- docs(js): add doc for `URL` - docs(js): stub doc for `URLSearchParams` Signed-off-by: Sam Gammon <[email protected]>
1 parent 9f285e1 commit 293ae08

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

Writerside/e.tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
</toc-element>
6464
<toc-element toc-title="Web &amp; JavaScript APIs">
6565
<toc-element topic="JavaScript-Encoding-API.md"/>
66+
<toc-element topic="JavaScript-URL-API.md"/>
6667
<toc-element toc-title="Fetch API" />
67-
<toc-element toc-title="URL API" />
6868
<toc-element toc-title="Web Crypto API" />
6969
<toc-element toc-title="Web Streams API" />
7070
</toc-element>

Writerside/topics/JavaScript-Encoding-API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Elide supports several encodings via the `TextEncoder` and `TextDecoder` constru
1717
| 🔴 Not supported yet. | `UTF_32` | `utf-32` | |
1818
| 🔴 Not supported yet. | (Other charsets) | | |
1919

20-
## Encoding API | Classes
20+
## Classes
2121

2222
[`TextEncoder`](#textencoder) Encode strings into byte array representations
2323
: 🟢 Supported.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# URL API
2+
3+
Elide supports the [WhatWG](https://whatwg.org) [URL API Specification](https://url.spec.whatwg.org/); this is the spec
4+
you use when you use the global `URL` class in JavaScript.
5+
6+
Elide's implementation of `URL` and `URLSearchParams` are based on JDK 22's
7+
[`URI`](https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.base/java/net/URI.html),
8+
[`URL`](https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.base/java/net/URL.html),
9+
and
10+
[`URLDecoder`](https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.base/java/net/URLDecoder.html)
11+
classes.
12+
13+
## Classes
14+
15+
[`URL`](#url) Parse and manipulate URLs
16+
: 🟢 Supported.
17+
18+
[`URLSearchParams`](#urlsearchparams) Parse and manipulate URL params
19+
: 🟢 Supported.
20+
21+
## `URL`
22+
23+
```Javascript
24+
const url = new URL('https://google.com/search')
25+
url.pathname // returns '/search'
26+
url.hostname // returns 'google.com'
27+
```
28+
29+
> Read more about the standard JavaScript `URL` class [on MDN](https://developer.mozilla.org/en-US/docs/Web/API/URL)
30+
31+
The `URL` class is used as a [value class](https://en.wikipedia.org/wiki/Value_object) which wraps a standard
32+
[Uniform Resource Locator](https://en.wikipedia.org/wiki/URL), also known as a "URL". URLs have a specific structure and
33+
suite of supported components, as opposed to their more general ancestor,
34+
[URIs](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier).
35+
36+
URLs are strictly validated: when you construct one from a string, it is parsed eagerly, and you will get an error if
37+
the provided string is not a valid URL.
38+
39+
URLs, by spec, support the following components:
40+
41+
| `URL` Property | Sample Value | Description |
42+
|-------------------------------------------------------------------------------------|----------------------------------------------|--------------------------------------------------------------------------------------------|
43+
| [`protocol`](https://developer.mozilla.org/en-US/docs/Web/API/URL/protocol) | `'https:'` | The transport technology in use, including the trailing `:`; usually `http:` or `https:` |
44+
| [`origin`](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin) | `'https://google.com:443'` | The web origin value of the URL; consists of the scheme, domain, and port |
45+
| [`host`](https://developer.mozilla.org/en-US/docs/Web/API/URL/host) | `'google.com:443'` | The full host string, like `https://google.com:443` from the example above |
46+
| [`hostname`](https://developer.mozilla.org/en-US/docs/Web/API/URL/hostname) | `'google.com'` | Just the hostname, like `google.com` from the sample above |
47+
| [`port`](https://developer.mozilla.org/en-US/docs/Web/API/URL/port) | `443` | Just the port, like `443` from the sample above (HTTPS) |
48+
| [`pathname`](https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname) | `/search` | The path portion of the url `/like-this/here`, or `/` at a minimum |
49+
| [`hash`](https://developer.mozilla.org/en-US/docs/Web/API/URL/hash) | `#hello` | The portion of the URL after `#`, if present |
50+
| [`href`](https://developer.mozilla.org/en-US/docs/Web/API/URL/href) | `'https://google.com/search'` | Formatted string version of the whole URL |
51+
| [`username`](https://developer.mozilla.org/en-US/docs/Web/API/URL/username) | `'user'` | If there is auth information in the URL (like `user:pass@...`), this is `user` |
52+
| [`password`](https://developer.mozilla.org/en-US/docs/Web/API/URL/password) | `'pass'` | `password`: If there is auth information in the URL (like `user:pass@...`), this is `pass` |
53+
| [`search`](https://developer.mozilla.org/en-US/docs/Web/API/URL/search) | `'?hello=hi'` | The portion of the URL after `?` but before `#`, if present, including the initial `?` |
54+
| [`searchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams) | [`URLSearchParams`](#urlsearchparams) object | Parsed `search` value into a multimap of key-value pairs |
55+
56+
## `URLSearchParams`
57+
58+
Coming soon.

0 commit comments

Comments
 (0)