bare-url 0.3.2 → 0.3.4
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/index.js +32 -8
- package/lib/parse.js +1 -1
- package/lib/serialize.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -32,11 +32,11 @@ const URL = exports.URL = class URL {
|
|
|
32
32
|
// https://url.spec.whatwg.org/#dom-url-protocol
|
|
33
33
|
|
|
34
34
|
get protocol () {
|
|
35
|
-
return
|
|
35
|
+
return this._url.scheme + ':'
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
set protocol (value) {
|
|
39
|
-
parse(
|
|
39
|
+
parse(value + ':', null, this._url, constants.STATE_SCHEME_START)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// https://url.spec.whatwg.org/#dom-url-username
|
|
@@ -73,7 +73,7 @@ const URL = exports.URL = class URL {
|
|
|
73
73
|
if (this._url.host === null) return ''
|
|
74
74
|
if (this._url.port === null) return this._url.host
|
|
75
75
|
|
|
76
|
-
return
|
|
76
|
+
return this._url.host + ':' + this._url.port
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
set host (value) {
|
|
@@ -101,7 +101,7 @@ const URL = exports.URL = class URL {
|
|
|
101
101
|
get port () {
|
|
102
102
|
if (this._url.port === null) return ''
|
|
103
103
|
|
|
104
|
-
return
|
|
104
|
+
return this._url.port.toString(10)
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
set port (value) {
|
|
@@ -123,7 +123,7 @@ const URL = exports.URL = class URL {
|
|
|
123
123
|
|
|
124
124
|
let output = ''
|
|
125
125
|
|
|
126
|
-
for (const segment of this._url.path) output +=
|
|
126
|
+
for (const segment of this._url.path) output += '/' + segment
|
|
127
127
|
|
|
128
128
|
return output
|
|
129
129
|
}
|
|
@@ -141,7 +141,7 @@ const URL = exports.URL = class URL {
|
|
|
141
141
|
get search () {
|
|
142
142
|
if (this._url.query === null || this._url.query === '') return ''
|
|
143
143
|
|
|
144
|
-
return
|
|
144
|
+
return '?' + this._url.query
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
set search (value) {
|
|
@@ -165,7 +165,7 @@ const URL = exports.URL = class URL {
|
|
|
165
165
|
get hash () {
|
|
166
166
|
if (this._url.fragment === null || this._url.fragment === '') return ''
|
|
167
167
|
|
|
168
|
-
return
|
|
168
|
+
return '#' + this._url.fragment
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
set hash (value) {
|
|
@@ -214,10 +214,34 @@ exports.fileURLToPath = function fileURLToPath (url) {
|
|
|
214
214
|
const pathname = path.normalize(decodeURIComponent(url.pathname))
|
|
215
215
|
|
|
216
216
|
if (os.platform() === 'win32') {
|
|
217
|
-
if (url.hostname) return
|
|
217
|
+
if (url.hostname) return '\\\\' + url.hostname + pathname
|
|
218
218
|
|
|
219
219
|
return pathname.slice(1)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
return pathname
|
|
223
223
|
}
|
|
224
|
+
|
|
225
|
+
exports.pathToFileURL = function pathToFileURL (pathname) {
|
|
226
|
+
let resolved = path.resolve(pathname)
|
|
227
|
+
|
|
228
|
+
if (pathname[pathname.length - 1] === '/') {
|
|
229
|
+
resolved += '/'
|
|
230
|
+
} else if (os.platform() === 'win32' && pathname[pathname.length - 1 === '\\']) {
|
|
231
|
+
resolved += '/'
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
resolved = resolved
|
|
235
|
+
.replaceAll('%', '%25') // Must be first
|
|
236
|
+
.replaceAll('#', '%23')
|
|
237
|
+
.replaceAll('?', '%3f')
|
|
238
|
+
.replaceAll('\n', '%0a')
|
|
239
|
+
.replaceAll('\r', '%0d')
|
|
240
|
+
.replaceAll('\t', '%09')
|
|
241
|
+
|
|
242
|
+
if (os.platform() !== 'win32') {
|
|
243
|
+
resolved = resolved.replaceAll('\\', '%5c')
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return new URL('file:' + resolved)
|
|
247
|
+
}
|
package/lib/parse.js
CHANGED
package/lib/serialize.js
CHANGED
|
@@ -34,7 +34,7 @@ module.exports = function serialize (url, excludeFragment = false) {
|
|
|
34
34
|
if (typeof url.path === 'string') {
|
|
35
35
|
output += url.path
|
|
36
36
|
} else {
|
|
37
|
-
output += '/' +
|
|
37
|
+
for (const segment of url.path) output += '/' + segment
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (url.query !== null) {
|