| | |
| | | * ```js |
| | | * import url from 'url'; |
| | | * ``` |
| | | * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/url.js) |
| | | * @see [source](https://github.com/nodejs/node/blob/v17.0.0/lib/url.js) |
| | | */ |
| | | declare module 'url' { |
| | | import { Blob } from 'node:buffer'; |
| | |
| | | function parse(urlString: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery; |
| | | function parse(urlString: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url; |
| | | /** |
| | | * The URL object has both a `toString()` method and `href` property that return string serializations of the URL. |
| | | * These are not, however, customizable in any way. The `url.format(URL[, options])` method allows for basic |
| | | * customization of the output. |
| | | * Returns a customizable serialization of a URL `String` representation of a `WHATWG URL` object. |
| | | * The `url.format()` method returns a formatted URL string derived from`urlObject`. |
| | | * |
| | | * ```js |
| | | * import url from 'url'; |
| | | * const myURL = new URL('https://a:b@測試?abc#foo'); |
| | | * const url = require('url'); |
| | | * url.format({ |
| | | * protocol: 'https', |
| | | * hostname: 'example.com', |
| | | * pathname: '/some/path', |
| | | * query: { |
| | | * page: 1, |
| | | * format: 'json' |
| | | * } |
| | | * }); |
| | | * |
| | | * console.log(myURL.href); |
| | | * // Prints https://a:b@xn--g6w251d/?abc#foo |
| | | * |
| | | * console.log(myURL.toString()); |
| | | * // Prints https://a:b@xn--g6w251d/?abc#foo |
| | | * |
| | | * console.log(url.format(myURL, { fragment: false, unicode: true, auth: false })); |
| | | * // Prints 'https://測試/?abc' |
| | | * // => 'https://example.com/some/path?page=1&format=json' |
| | | * ``` |
| | | * @since v7.6.0 |
| | | * @param urlObject A `WHATWG URL` object |
| | | * @param options |
| | | * |
| | | * If `urlObject` is not an object or a string, `url.format()` will throw a `TypeError`. |
| | | * |
| | | * The formatting process operates as follows: |
| | | * |
| | | * * A new empty string `result` is created. |
| | | * * If `urlObject.protocol` is a string, it is appended as-is to `result`. |
| | | * * Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown. |
| | | * * For all string values of `urlObject.protocol` that _do not end_ with an ASCII |
| | | * colon (`:`) character, the literal string `:` will be appended to `result`. |
| | | * * If either of the following conditions is true, then the literal string `//`will be appended to `result`: |
| | | * * `urlObject.slashes` property is true; |
| | | * * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or`file`; |
| | | * * If the value of the `urlObject.auth` property is truthy, and either`urlObject.host` or `urlObject.hostname` are not `undefined`, the value of`urlObject.auth` will be coerced into a string |
| | | * and appended to `result`followed by the literal string `@`. |
| | | * * If the `urlObject.host` property is `undefined` then: |
| | | * * If the `urlObject.hostname` is a string, it is appended to `result`. |
| | | * * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string, |
| | | * an `Error` is thrown. |
| | | * * If the `urlObject.port` property value is truthy, and `urlObject.hostname`is not `undefined`: |
| | | * * The literal string `:` is appended to `result`, and |
| | | * * The value of `urlObject.port` is coerced to a string and appended to`result`. |
| | | * * Otherwise, if the `urlObject.host` property value is truthy, the value of`urlObject.host` is coerced to a string and appended to `result`. |
| | | * * If the `urlObject.pathname` property is a string that is not an empty string: |
| | | * * If the `urlObject.pathname`_does not start_ with an ASCII forward slash |
| | | * (`/`), then the literal string `'/'` is appended to `result`. |
| | | * * The value of `urlObject.pathname` is appended to `result`. |
| | | * * Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown. |
| | | * * If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result`followed by the output of calling the |
| | | * `querystring` module's `stringify()`method passing the value of `urlObject.query`. |
| | | * * Otherwise, if `urlObject.search` is a string: |
| | | * * If the value of `urlObject.search`_does not start_ with the ASCII question |
| | | * mark (`?`) character, the literal string `?` is appended to `result`. |
| | | * * The value of `urlObject.search` is appended to `result`. |
| | | * * Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown. |
| | | * * If the `urlObject.hash` property is a string: |
| | | * * If the value of `urlObject.hash`_does not start_ with the ASCII hash (`#`) |
| | | * character, the literal string `#` is appended to `result`. |
| | | * * The value of `urlObject.hash` is appended to `result`. |
| | | * * Otherwise, if the `urlObject.hash` property is not `undefined` and is not a |
| | | * string, an `Error` is thrown. |
| | | * * `result` is returned. |
| | | * @since v0.1.25 |
| | | * @deprecated Legacy: Use the WHATWG URL API instead. |
| | | * @param urlObject A URL object (as returned by `url.parse()` or constructed otherwise). If a string, it is converted to an object by passing it to `url.parse()`. |
| | | */ |
| | | function format(urlObject: URL, options?: URLFormatOptions): string; |
| | | /** |
| | |
| | | * } |
| | | * |
| | | * ``` |
| | | * @since v15.7.0 |
| | | * @since v15.7.0, v14.18.0 |
| | | * @param url The `WHATWG URL` object to convert to an options object. |
| | | * @return Options object |
| | | */ |
| | |
| | | * @param fn Invoked for each name-value pair in the query |
| | | * @param thisArg To be used as `this` value for when `fn` is called |
| | | */ |
| | | forEach<TThis = this>(callback: (this: TThis, value: string, name: string, searchParams: this) => void, thisArg?: TThis): void; |
| | | forEach<TThis = this>(callback: (this: TThis, value: string, name: string, searchParams: URLSearchParams) => void, thisArg?: TThis): void; |
| | | /** |
| | | * Returns the value of the first name-value pair whose name is `name`. If there |
| | | * are no such pairs, `null` is returned. |
| | |
| | | values(): IterableIterator<string>; |
| | | [Symbol.iterator](): IterableIterator<[string, string]>; |
| | | } |
| | | |
| | | import { URL as _URL, URLSearchParams as _URLSearchParams } from 'url'; |
| | | global { |
| | | interface URLSearchParams extends _URLSearchParams {} |
| | | interface URL extends _URL {} |
| | | interface Global { |
| | | URL: typeof _URL; |
| | | URLSearchParams: typeof _URLSearchParams; |
| | | } |
| | | /** |
| | | * `URL` class is a global reference for `require('url').URL` |
| | | * https://nodejs.org/api/url.html#the-whatwg-url-api |
| | | * @since v10.0.0 |
| | | */ |
| | | var URL: |
| | | // For compatibility with "dom" and "webworker" URL declarations |
| | | typeof globalThis extends { onmessage: any, URL: infer URL } |
| | | ? URL |
| | | : typeof _URL; |
| | | /** |
| | | * `URLSearchParams` class is a global reference for `require('url').URLSearchParams` |
| | | * https://nodejs.org/api/url.html#class-urlsearchparams |
| | | * @since v10.0.0 |
| | | */ |
| | | var URLSearchParams: |
| | | // For compatibility with "dom" and "webworker" URLSearchParams declarations |
| | | typeof globalThis extends { onmessage: any, URLSearchParams: infer URLSearchParams } |
| | | ? URLSearchParams |
| | | : typeof _URLSearchParams; |
| | | } |
| | | } |
| | | declare module 'node:url' { |
| | | export * from 'url'; |