bare-url 2.4.1 → 2.4.3

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/CMakeLists.txt CHANGED
@@ -6,7 +6,7 @@ find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch)
6
6
  project(bare_url C)
7
7
 
8
8
  fetch_package("github:holepunchto/libutf#6b1a36f")
9
- fetch_package("github:holepunchto/liburl#03f1488")
9
+ fetch_package("github:holepunchto/liburl#2215632")
10
10
 
11
11
  add_bare_module(bare_url)
12
12
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # bare-url
2
2
 
3
- WHATWG URL implementation for JavaScript.
3
+ WHATWG URL implementation for JavaScript, built on <https://github.com/holepunchto/liburl>. Provides `URL` and `URLSearchParams` classes compatible with the WHATWG URL Standard.
4
4
 
5
5
  ```
6
6
  npm i bare-url
@@ -9,11 +9,164 @@ npm i bare-url
9
9
  ## Usage
10
10
 
11
11
  ```js
12
- const url = require('bare-url')
12
+ const { URL, URLSearchParams } = require('bare-url')
13
13
 
14
- const p = url.fileURLToPath('file:///foo') // --> /foo
14
+ const url = new URL('https://example.com/path?foo=bar#hash')
15
+
16
+ console.log(url.hostname) // 'example.com'
17
+ console.log(url.pathname) // '/path'
18
+ console.log(url.searchParams.get('foo')) // 'bar'
19
+ ```
20
+
21
+ To register `URL` and `URLSearchParams` as globals:
22
+
23
+ ```js
24
+ require('bare-url/global')
25
+ ```
26
+
27
+ ## API
28
+
29
+ #### `const url = new URL(input[, base])`
30
+
31
+ Parse `input` as a URL. If `base` is provided, `input` is resolved relative to `base`. Throws if `input` is not a valid URL.
32
+
33
+ #### `url.href`
34
+
35
+ The full serialized URL string. Setting this property reparses the URL.
36
+
37
+ #### `url.protocol`
38
+
39
+ The URL scheme followed by `':'`, e.g. `'https:'`.
40
+
41
+ #### `url.username`
42
+
43
+ The username portion of the URL, or an empty string.
44
+
45
+ #### `url.password`
46
+
47
+ The password portion of the URL, or an empty string.
48
+
49
+ #### `url.host`
50
+
51
+ The hostname and port, e.g. `'example.com:8080'`.
52
+
53
+ #### `url.hostname`
54
+
55
+ The hostname without the port.
56
+
57
+ #### `url.port`
58
+
59
+ The port as a string, or an empty string if not present.
60
+
61
+ #### `url.pathname`
62
+
63
+ The path portion of the URL.
64
+
65
+ #### `url.search`
66
+
67
+ The query string including the leading `'?'`, or an empty string.
68
+
69
+ #### `url.searchParams`
70
+
71
+ A `URLSearchParams` object for the query string. Mutations to the params are reflected in the URL.
72
+
73
+ #### `url.hash`
74
+
75
+ The fragment including the leading `'#'`, or an empty string.
76
+
77
+ #### `url.toString()`
78
+
79
+ Returns the serialized URL string. Equivalent to `url.href`.
80
+
81
+ #### `url.toJSON()`
82
+
83
+ Returns the serialized URL string. Suitable for JSON serialization.
84
+
85
+ #### `const params = new URLSearchParams([init])`
86
+
87
+ Create a new `URLSearchParams` instance. `init` may be a query string, an iterable of `[name, value]` pairs, or an object of key-value pairs.
88
+
89
+ #### `params.size`
90
+
91
+ The total number of search parameters.
92
+
93
+ #### `params.append(name, value)`
94
+
95
+ Append a new `name`/`value` pair.
96
+
97
+ #### `params.delete(name[, value])`
98
+
99
+ Remove all pairs with `name`. If `value` is provided, only pairs with both the matching `name` and `value` are removed.
100
+
101
+ #### `params.get(name)`
102
+
103
+ Return the first value for `name`, or `null` if not present.
104
+
105
+ #### `params.getAll(name)`
106
+
107
+ Return all values for `name` as an array.
108
+
109
+ #### `params.has(name[, value])`
110
+
111
+ Return `true` if a pair with `name` exists. If `value` is provided, the pair must also match `value`.
112
+
113
+ #### `params.set(name, value)`
114
+
115
+ Set the value for `name`, replacing any existing pairs with that name.
116
+
117
+ #### `params.toString()`
118
+
119
+ Return the serialized query string without the leading `'?'`.
120
+
121
+ #### `params.toJSON()`
122
+
123
+ Return the parameters as an array of `[name, value]` pairs.
124
+
125
+ #### `URL.isURL(value)`
126
+
127
+ Return `true` if `value` is a `URL` instance.
128
+
129
+ #### `URLSearchParams.isURLSearchParams(value)`
130
+
131
+ Return `true` if `value` is a `URLSearchParams` instance.
132
+
133
+ #### `const url = URL.parse(input[, base])`
134
+
135
+ Parse `input` as a URL without throwing. Returns a `URL` instance on success, or `null` on failure.
136
+
137
+ #### `const valid = URL.canParse(input[, base])`
138
+
139
+ Return `true` if `input` can be parsed as a valid URL, optionally relative to `base`.
140
+
141
+ #### `const pathname = URL.fileURLToPath(url)`
142
+
143
+ Convert a `file:` URL to a platform-specific file path. `url` may be a `URL` instance or a string. Throws if the URL does not use the `file:` protocol or contains invalid path characters.
144
+
145
+ #### `const url = URL.pathToFileURL(pathname)`
146
+
147
+ Convert a platform-specific file path to a `file:` URL.
148
+
149
+ #### `const href = URL.format(parts)`
150
+
151
+ Format a URL from individual `parts`:
152
+
153
+ ```js
154
+ parts = {
155
+ protocol,
156
+ auth,
157
+ host,
158
+ hostname,
159
+ port,
160
+ pathname,
161
+ search,
162
+ query,
163
+ hash,
164
+ slashes
165
+ }
15
166
  ```
16
167
 
168
+ All properties are optional. If `host` is provided, `hostname` and `port` are ignored. If `search` is provided, `query` is ignored. Set `slashes` to `true` to include `'//'` after the protocol.
169
+
17
170
  ## License
18
171
 
19
172
  Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-url",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "WHATWG URL implementation for JavaScript",
5
5
  "exports": {
6
6
  "./package": "./package.json",
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file