Place
A URL, declared. The exact address, as data.
place() takes a URL and returns it as a declaration: its parts, and the exact address they rebuild. Nothing is
guessed and nothing is lost.
import { place, formatPlace, decodePart, queryEntries } from 'this.url/place';
const p = place('https://es.wikipedia.org/wiki/Pastor_alemán?oldid=123&lang=es#Historia');
{
"input": "https://es.wikipedia.org/wiki/Pastor_alemán?oldid=123&lang=es#Historia",
"href": "https://es.wikipedia.org/wiki/Pastor_alem%C3%A1n?oldid=123&lang=es#Historia",
"scheme": "https",
"host": "es.wikipedia.org",
"path": ["wiki", "Pastor_alem%C3%A1n"],
"query": [{ "name": "oldid", "value": "123" }, { "name": "lang", "value": "es" }],
"fragment": "Historia"
}
| Field | What it is |
|---|---|
input |
the text it was given, exactly |
href |
the exact, normalized address (what a browser would use) |
scheme, host |
https, es.wikipedia.org (the port, when there is one, is part of host) |
path |
the path as segments, raw: a%2Fb is one segment, never a/b |
query |
the query as an ordered list: repeated names, their order, a vs a= all kept; null when there is no ? |
fragment |
the part after #; null when there is no #, "" for a bare # |
The guarantee
formatPlace(place(x)) is always place(x).href. The parts rebuild the exact address, for every URL it accepts.
For reading, the raw parts have decoded views:
p.path.map(decodePart) // ["wiki", "Pastor_alemán"]
queryEntries(p) // [["oldid", "123"], ["lang", "es"]]
What is not a place
place() refuses what is not a page address: text that is not a URL, javascript:, data:, mailto:, and any URL
with credentials in it (https://user:pass@…, https://cleaker.me@evil.example/).
Where it goes next
A declared place can be handed to Cleaker to navigate, shown by .GUI, or given to this.DOM, which declares what is inside the page: the elements, and the exact lines (see URL and DOM).
URL → this.url (place) → this.DOM (inside the page) → .GUI / Cleaker
Optional: keeping a place in .me
Declaring a place needs nothing else. Keeping one in a .me tree is an extra, for when you choose to save it:
this.url/placealso hasdeclareUrl/saveUrl: the place as athis.urlrecord atweb.pages.page_<random id>, found again throughme://<your namespace>:read/web.pages.<id>.this.url/sealedkeeps a private place: sealed for an audience with.meaudiences, so only its members open it.
Neither is required to declare a URL or to read its DOM.
Status
Declaring a URL (place, formatPlace) |
done, tested |
Entry this.url (also this.url/place) |
done |
Following links: crawl (a page’s links, resolved, as a graph), walk (chosen links, .me selectors) |
done, tested |
Reading pages: this.url/reader, your own machine (private networks refused unless allowed) |
done, tested |
| When two URLs are the same place | only identical addresses, for now |
| Published on npm | 2.0.0 |
See also
- URL and DOM: A page, and a place inside it.