+13
-58
@@ -52,5 +52,3 @@ const path = require('bare-path') | ||
| set protocol(value) { | ||
| this._update( | ||
| this._replace(value.replace(/:+$/, ''), 0, this._components[0]) | ||
| ) | ||
| this._update(this._replace(value.replace(/:+$/, ''), 0, this._components[0])) | ||
| } | ||
@@ -71,9 +69,3 @@ | ||
| this._update( | ||
| this._replace( | ||
| value, | ||
| this._components[0] + 3 /* :// */, | ||
| this._components[1] | ||
| ) | ||
| ) | ||
| this._update(this._replace(value, this._components[0] + 3 /* :// */, this._components[1])) | ||
| } | ||
@@ -84,6 +76,3 @@ | ||
| get password() { | ||
| return this._href.slice( | ||
| this._components[1] + 1 /* : */, | ||
| this._components[2] - 1 /* @ */ | ||
| ) | ||
| return this._href.slice(this._components[1] + 1 /* : */, this._components[2] - 1 /* @ */) | ||
| } | ||
@@ -124,7 +113,3 @@ | ||
| this._update( | ||
| this._replace( | ||
| value, | ||
| this._components[2], | ||
| this._components[value.includes(':') ? 5 : 3] | ||
| ) | ||
| this._replace(value, this._components[2], this._components[value.includes(':') ? 5 : 3]) | ||
| ) | ||
@@ -183,5 +168,3 @@ } | ||
| this._update( | ||
| this._replace(value, this._components[5], this._components[6] - 1 /* ? */) | ||
| ) | ||
| this._update(this._replace(value, this._components[5], this._components[6] - 1 /* ? */)) | ||
| } | ||
@@ -192,6 +175,3 @@ | ||
| get search() { | ||
| return this._slice( | ||
| this._components[6] - 1 /* ? */, | ||
| this._components[7] - 1 /* # */ | ||
| ) | ||
| return this._slice(this._components[6] - 1 /* ? */, this._components[7] - 1 /* # */) | ||
| } | ||
@@ -203,7 +183,3 @@ | ||
| this._update( | ||
| this._replace( | ||
| value, | ||
| this._components[6] - 1 /* ? */, | ||
| this._components[7] - 1 /* # */ | ||
| ) | ||
| this._replace(value, this._components[6] - 1 /* ? */, this._components[7] - 1 /* # */) | ||
| ) | ||
@@ -277,3 +253,3 @@ | ||
| throw errors.INVALID_URL() | ||
| throw errors.INVALID_URL(`Invalid URL '${input}'`, input) | ||
| } | ||
@@ -311,5 +287,3 @@ } | ||
| return ( | ||
| typeof value === 'object' && value !== null && value[kind] === URL[kind] | ||
| ) | ||
| return typeof value === 'object' && value !== null && value[kind] === URL[kind] | ||
| } | ||
@@ -345,11 +319,7 @@ | ||
| if (url.hostname) { | ||
| throw errors.INVALID_FILE_URL_HOST( | ||
| "The file: URL host must be 'localhost' or empty" | ||
| ) | ||
| throw errors.INVALID_FILE_URL_HOST("The file: URL host must be 'localhost' or empty") | ||
| } | ||
| if (/%2f/i.test(url.pathname)) { | ||
| throw errors.INVALID_FILE_URL_PATH( | ||
| 'The file: URL path must not include encoded / characters' | ||
| ) | ||
| throw errors.INVALID_FILE_URL_PATH('The file: URL path must not include encoded / characters') | ||
| } | ||
@@ -365,7 +335,3 @@ } | ||
| if ( | ||
| letter < 0x61 /* a */ || | ||
| letter > 0x7a /* z */ || | ||
| pathname.charCodeAt(2) !== 0x3a /* : */ | ||
| ) { | ||
| if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) { | ||
| throw errors.INVALID_FILE_URL_PATH('The file: URL path must be absolute') | ||
@@ -405,14 +371,3 @@ } | ||
| exports.format = function format(parts) { | ||
| const { | ||
| protocol, | ||
| auth, | ||
| host, | ||
| hostname, | ||
| port, | ||
| pathname, | ||
| search, | ||
| query, | ||
| hash, | ||
| slashes | ||
| } = parts | ||
| const { protocol, auth, host, hostname, port, pathname, search, query, hash, slashes } = parts | ||
@@ -419,0 +374,0 @@ let result = '' |
+6
-4
@@ -0,8 +1,10 @@ | ||
| interface URLError extends Error { | ||
| readonly code: string | ||
| readonly input?: string | ||
| } | ||
| declare class URLError extends Error { | ||
| static INVALID_URL(msg?: string): URLError | ||
| static INVALID_URL_SCHEME(msg?: string): URLError | ||
| static INVALID_FILE_URL_HOST(msg?: string): URLError | ||
| static INVALID_FILE_URL_PATH(msg?: string): URLError | ||
| private constructor() | ||
| } | ||
| export = URLError |
+12
-17
| module.exports = class URLError extends Error { | ||
| constructor(msg, code, fn = URLError) { | ||
| constructor(msg, fn = URLError, code = fn.name) { | ||
| super(`${code}: ${msg}`) | ||
| this.code = code | ||
| if (Error.captureStackTrace) { | ||
| Error.captureStackTrace(this, fn) | ||
| } | ||
| if (Error.captureStackTrace) Error.captureStackTrace(this, fn) | ||
| } | ||
@@ -15,25 +14,21 @@ | ||
| static INVALID_URL(msg = 'Invalid URL') { | ||
| return new URLError(msg, 'INVALID_URL', URLError.INVALID_URL) | ||
| static INVALID_URL(msg, input) { | ||
| const err = new URLError(msg, URLError.INVALID_URL) | ||
| err.input = input | ||
| return err | ||
| } | ||
| static INVALID_URL_SCHEME(msg = 'Invalid URL') { | ||
| return new URLError(msg, 'INVALID_URL_SCHEME', URLError.INVALID_URL_SCHEME) | ||
| return new URLError(msg, URLError.INVALID_URL_SCHEME) | ||
| } | ||
| static INVALID_FILE_URL_HOST(msg = 'Invalid file: URL host') { | ||
| return new URLError( | ||
| msg, | ||
| 'INVALID_FILE_URL_HOST', | ||
| URLError.INVALID_FILE_URL_HOST | ||
| ) | ||
| return new URLError(msg, URLError.INVALID_FILE_URL_HOST) | ||
| } | ||
| static INVALID_FILE_URL_PATH(msg = 'Invalid file: URL path') { | ||
| return new URLError( | ||
| msg, | ||
| 'INVALID_FILE_URL_PATH', | ||
| URLError.INVALID_FILE_URL_PATH | ||
| ) | ||
| return new URLError(msg, URLError.INVALID_FILE_URL_PATH) | ||
| } | ||
| } |
@@ -16,7 +16,5 @@ interface URLSearchParams extends Iterable<[name: string, value: string]> { | ||
| declare class URLSearchParams { | ||
| constructor( | ||
| init: string | Record<string, string> | Iterable<[string, string]> | ||
| ) | ||
| constructor(init: string | Record<string, string> | Iterable<[string, string]>) | ||
| } | ||
| export = URLSearchParams |
@@ -145,5 +145,3 @@ module.exports = class URLSearchParams { | ||
| const name = decodeURIComponent(sequence.substring(0, i)) | ||
| const value = decodeURIComponent( | ||
| sequence.substring(i + 1, sequence.length) | ||
| ) | ||
| const value = decodeURIComponent(sequence.substring(i + 1, sequence.length)) | ||
@@ -150,0 +148,0 @@ let list = this._params.get(name) |
+2
-2
| { | ||
| "name": "bare-url", | ||
| "version": "2.3.1", | ||
| "version": "2.3.2", | ||
| "description": "WHATWG URL implementation for JavaScript", | ||
@@ -49,4 +49,4 @@ "exports": { | ||
| "prettier": "^3.3.3", | ||
| "prettier-config-standard": "^7.0.0" | ||
| "prettier-config-holepunch": "^2.0.0" | ||
| } | ||
| } |
1518063
-0.03%515
-9.81%