bare-url 2.3.1 → 2.3.2

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 CHANGED
@@ -49,9 +49,7 @@ module.exports = exports = class URL {
49
49
  }
50
50
 
51
51
  set protocol(value) {
52
- this._update(
53
- this._replace(value.replace(/:+$/, ''), 0, this._components[0])
54
- )
52
+ this._update(this._replace(value.replace(/:+$/, ''), 0, this._components[0]))
55
53
  }
56
54
 
57
55
  // https://url.spec.whatwg.org/#dom-url-username
@@ -67,22 +65,13 @@ module.exports = exports = class URL {
67
65
 
68
66
  if (this.username === '') value += '@'
69
67
 
70
- this._update(
71
- this._replace(
72
- value,
73
- this._components[0] + 3 /* :// */,
74
- this._components[1]
75
- )
76
- )
68
+ this._update(this._replace(value, this._components[0] + 3 /* :// */, this._components[1]))
77
69
  }
78
70
 
79
71
  // https://url.spec.whatwg.org/#dom-url-password
80
72
 
81
73
  get password() {
82
- return this._href.slice(
83
- this._components[1] + 1 /* : */,
84
- this._components[2] - 1 /* @ */
85
- )
74
+ return this._href.slice(this._components[1] + 1 /* : */, this._components[2] - 1 /* @ */)
86
75
  }
87
76
 
88
77
  set password(value) {
@@ -118,11 +107,7 @@ module.exports = exports = class URL {
118
107
  }
119
108
 
120
109
  this._update(
121
- this._replace(
122
- value,
123
- this._components[2],
124
- this._components[value.includes(':') ? 5 : 3]
125
- )
110
+ this._replace(value, this._components[2], this._components[value.includes(':') ? 5 : 3])
126
111
  )
127
112
  }
128
113
 
@@ -176,29 +161,20 @@ module.exports = exports = class URL {
176
161
  value = '/' + value
177
162
  }
178
163
 
179
- this._update(
180
- this._replace(value, this._components[5], this._components[6] - 1 /* ? */)
181
- )
164
+ this._update(this._replace(value, this._components[5], this._components[6] - 1 /* ? */))
182
165
  }
183
166
 
184
167
  // https://url.spec.whatwg.org/#dom-url-search
185
168
 
186
169
  get search() {
187
- return this._slice(
188
- this._components[6] - 1 /* ? */,
189
- this._components[7] - 1 /* # */
190
- )
170
+ return this._slice(this._components[6] - 1 /* ? */, this._components[7] - 1 /* # */)
191
171
  }
192
172
 
193
173
  set search(value) {
194
174
  if (value && value[0] !== '?') value = '?' + value
195
175
 
196
176
  this._update(
197
- this._replace(
198
- value,
199
- this._components[6] - 1 /* ? */,
200
- this._components[7] - 1 /* # */
201
- )
177
+ this._replace(value, this._components[6] - 1 /* ? */, this._components[7] - 1 /* # */)
202
178
  )
203
179
 
204
180
  this._params._parse(this.search)
@@ -267,7 +243,7 @@ module.exports = exports = class URL {
267
243
  } catch (err) {
268
244
  if (err instanceof TypeError) throw err
269
245
 
270
- throw errors.INVALID_URL()
246
+ throw errors.INVALID_URL(`Invalid URL '${input}'`, input)
271
247
  }
272
248
  }
273
249
 
@@ -300,9 +276,7 @@ exports.errors = errors
300
276
  exports.isURL = function isURL(value) {
301
277
  if (value instanceof URL) return true
302
278
 
303
- return (
304
- typeof value === 'object' && value !== null && value[kind] === URL[kind]
305
- )
279
+ return typeof value === 'object' && value !== null && value[kind] === URL[kind]
306
280
  }
307
281
 
308
282
  // https://url.spec.whatwg.org/#dom-url-parse
@@ -333,15 +307,11 @@ exports.fileURLToPath = function fileURLToPath(url) {
333
307
  }
334
308
  } else {
335
309
  if (url.hostname) {
336
- throw errors.INVALID_FILE_URL_HOST(
337
- "The file: URL host must be 'localhost' or empty"
338
- )
310
+ throw errors.INVALID_FILE_URL_HOST("The file: URL host must be 'localhost' or empty")
339
311
  }
340
312
 
341
313
  if (/%2f/i.test(url.pathname)) {
342
- throw errors.INVALID_FILE_URL_PATH(
343
- 'The file: URL path must not include encoded / characters'
344
- )
314
+ throw errors.INVALID_FILE_URL_PATH('The file: URL path must not include encoded / characters')
345
315
  }
346
316
  }
347
317
 
@@ -352,11 +322,7 @@ exports.fileURLToPath = function fileURLToPath(url) {
352
322
 
353
323
  const letter = pathname.charCodeAt(1) | 0x20
354
324
 
355
- if (
356
- letter < 0x61 /* a */ ||
357
- letter > 0x7a /* z */ ||
358
- pathname.charCodeAt(2) !== 0x3a /* : */
359
- ) {
325
+ if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {
360
326
  throw errors.INVALID_FILE_URL_PATH('The file: URL path must be absolute')
361
327
  }
362
328
 
@@ -391,18 +357,7 @@ exports.pathToFileURL = function pathToFileURL(pathname) {
391
357
  }
392
358
 
393
359
  exports.format = function format(parts) {
394
- const {
395
- protocol,
396
- auth,
397
- host,
398
- hostname,
399
- port,
400
- pathname,
401
- search,
402
- query,
403
- hash,
404
- slashes
405
- } = parts
360
+ const { protocol, auth, host, hostname, port, pathname, search, query, hash, slashes } = parts
406
361
 
407
362
  let result = ''
408
363
 
package/lib/errors.d.ts CHANGED
@@ -1,8 +1,10 @@
1
+ interface URLError extends Error {
2
+ readonly code: string
3
+ readonly input?: string
4
+ }
5
+
1
6
  declare class URLError extends Error {
2
- static INVALID_URL(msg?: string): URLError
3
- static INVALID_URL_SCHEME(msg?: string): URLError
4
- static INVALID_FILE_URL_HOST(msg?: string): URLError
5
- static INVALID_FILE_URL_PATH(msg?: string): URLError
7
+ private constructor()
6
8
  }
7
9
 
8
10
  export = URLError
package/lib/errors.js CHANGED
@@ -1,38 +1,33 @@
1
1
  module.exports = class URLError extends Error {
2
- constructor(msg, code, fn = URLError) {
2
+ constructor(msg, fn = URLError, code = fn.name) {
3
3
  super(`${code}: ${msg}`)
4
+
4
5
  this.code = code
5
6
 
6
- if (Error.captureStackTrace) {
7
- Error.captureStackTrace(this, fn)
8
- }
7
+ if (Error.captureStackTrace) Error.captureStackTrace(this, fn)
9
8
  }
10
9
 
11
10
  get name() {
12
11
  return 'URLError'
13
12
  }
14
13
 
15
- static INVALID_URL(msg = 'Invalid URL') {
16
- return new URLError(msg, 'INVALID_URL', URLError.INVALID_URL)
14
+ static INVALID_URL(msg, input) {
15
+ const err = new URLError(msg, URLError.INVALID_URL)
16
+
17
+ err.input = input
18
+
19
+ return err
17
20
  }
18
21
 
19
22
  static INVALID_URL_SCHEME(msg = 'Invalid URL') {
20
- return new URLError(msg, 'INVALID_URL_SCHEME', URLError.INVALID_URL_SCHEME)
23
+ return new URLError(msg, URLError.INVALID_URL_SCHEME)
21
24
  }
22
25
 
23
26
  static INVALID_FILE_URL_HOST(msg = 'Invalid file: URL host') {
24
- return new URLError(
25
- msg,
26
- 'INVALID_FILE_URL_HOST',
27
- URLError.INVALID_FILE_URL_HOST
28
- )
27
+ return new URLError(msg, URLError.INVALID_FILE_URL_HOST)
29
28
  }
30
29
 
31
30
  static INVALID_FILE_URL_PATH(msg = 'Invalid file: URL path') {
32
- return new URLError(
33
- msg,
34
- 'INVALID_FILE_URL_PATH',
35
- URLError.INVALID_FILE_URL_PATH
36
- )
31
+ return new URLError(msg, URLError.INVALID_FILE_URL_PATH)
37
32
  }
38
33
  }
@@ -13,9 +13,7 @@ interface URLSearchParams extends Iterable<[name: string, value: string]> {
13
13
  }
14
14
 
15
15
  declare class URLSearchParams {
16
- constructor(
17
- init: string | Record<string, string> | Iterable<[string, string]>
18
- )
16
+ constructor(init: string | Record<string, string> | Iterable<[string, string]>)
19
17
  }
20
18
 
21
19
  export = URLSearchParams
@@ -142,9 +142,7 @@ module.exports = class URLSearchParams {
142
142
  if (i === -1) i = sequence.length
143
143
 
144
144
  const name = decodeURIComponent(sequence.substring(0, i))
145
- const value = decodeURIComponent(
146
- sequence.substring(i + 1, sequence.length)
147
- )
145
+ const value = decodeURIComponent(sequence.substring(i + 1, sequence.length))
148
146
 
149
147
  let list = this._params.get(name)
150
148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-url",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "WHATWG URL implementation for JavaScript",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -46,6 +46,6 @@
46
46
  "cmake-bare": "^1.1.6",
47
47
  "cmake-fetch": "^1.0.0",
48
48
  "prettier": "^3.3.3",
49
- "prettier-config-standard": "^7.0.0"
49
+ "prettier-config-holepunch": "^2.0.0"
50
50
  }
51
51
  }