You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-6Lines changed: 43 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,19 +14,49 @@ URL Tools is a helper library whose sole purpose is making that process just a l
14
14
`npm install @autogram/url-tools`
15
15
16
16
## Usage
17
+
`ParsedUrl` and `NormalizedUrl` are meant to work as drop-in replacements for the built-in `URL` class.
17
18
18
-
UrlSet is the simplest example; toss URLs at it, and parsed URLs come out. Any that couldn't be parsed can be found the `urlSet.unparsable` property.
19
+
```
20
+
import { ParsedUrl } from '@autogram/url-tools';
21
+
22
+
const p = new ParsedUrl('http://staging.foo.com');
23
+
console.log(p.domain); // 'foo.com';
24
+
console.log(p.subdomain); // 'staging';
25
+
```
26
+
27
+
### URL scrubbing and normalization
28
+
`NormalizedUrl` applies a given `UrlMutator` function after it parses incoming URLs; by default it applies the relatively aggressive `UrlMutator.defaultNormalizer`; it strips off 'www' subdomains, `utm` querystring parameters, authentication information, ports, common index pages like `index.html` and `default.aspx`, page anchors, and more. It also enforces lowercasing of hostnames, and alphabetizes all remaining queryString parameters.
29
+
30
+
Individual rules are broken out into discrete `UrlMutator` functions for easy composition of alternate rulesets, and any function that accepts a `NormalizedUrl` and returns a `NormalizedUrl` can be passed in to implement custom rules.
31
+
32
+
```
33
+
import { NormalizedUrl } from '@autogram/url-tools';
UrlSet is the simplest of the collection classes; toss URLs at it, and parsed URLs come out. Any that couldn't be parsed can be found the `urlSet.unparsable` property.
Both `ParsedUrlSet` and `NormalizedUrlSet` can accept a `UrlFilter` function in their constructor options; incoming URLs rejected by that function are shunted to the Set's `parsedUrlSet.rejected` property and not added to the Set proper.
39
70
40
71
`NormalizedUrlSet` can rely rely on NormalizedUrl's aggressive defaults, or pass in a UrlMutator function to use as an override.
41
72
42
73
```
43
74
import { NormalizedUrlSet, UrlFilters, UrlMutators } from '@autogram/url-tools';
0 commit comments