diff options
Diffstat (limited to 'ext/url/lib.deno_url.d.ts')
-rw-r--r-- | ext/url/lib.deno_url.d.ts | 88 |
1 files changed, 67 insertions, 21 deletions
diff --git a/ext/url/lib.deno_url.d.ts b/ext/url/lib.deno_url.d.ts index 9a8c155d9..6da1c5704 100644 --- a/ext/url/lib.deno_url.d.ts +++ b/ext/url/lib.deno_url.d.ts @@ -1,17 +1,12 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// deno-lint-ignore-file no-explicit-any +// deno-lint-ignore-file no-explicit-any no-var /// <reference no-default-lib="true" /> /// <reference lib="esnext" /> /** @category Web APIs */ -declare class URLSearchParams { - constructor( - init?: string[][] | Record<string, string> | string | URLSearchParams, - ); - static toString(): string; - +declare interface URLSearchParams { /** Appends a specified key/value pair as a new search parameter. * * ```ts @@ -22,15 +17,16 @@ declare class URLSearchParams { */ append(name: string, value: string): void; - /** Deletes the given search parameter and its associated value, + /** Deletes search parameters that match a name, and optional value, * from the list of all search parameters. * * ```ts * let searchParams = new URLSearchParams([['name', 'value']]); * searchParams.delete('name'); + * searchParams.delete('name', 'value'); * ``` */ - delete(name: string): void; + delete(name: string, value?: string): void; /** Returns all the values associated with a given search parameter * as an array. @@ -49,14 +45,15 @@ declare class URLSearchParams { */ get(name: string): string | null; - /** Returns a Boolean that indicates whether a parameter with the - * specified name exists. + /** Returns a boolean value indicating if a given parameter, + * or parameter and value pair, exists. * * ```ts * searchParams.has('name'); + * searchParams.has('name', 'value'); * ``` */ - has(name: string): boolean; + has(name: string, value?: string): boolean; /** Sets the value associated with a given search parameter to the * given value. If there were several matching values, this method @@ -160,17 +157,20 @@ declare class URLSearchParams { size: number; } +/** @category Web APIs */ +declare var URLSearchParams: { + readonly prototype: URLSearchParams; + new ( + init?: Iterable<string[]> | Record<string, string> | string, + ): URLSearchParams; +}; + /** The URL interface represents an object providing static methods used for * creating object URLs. * * @category Web APIs */ -declare class URL { - constructor(url: string | URL, base?: string | URL); - static canParse(url: string | URL, base?: string | URL): boolean; - static createObjectURL(blob: Blob): string; - static revokeObjectURL(url: string): void; - +declare interface URL { hash: string; host: string; hostname: string; @@ -187,6 +187,19 @@ declare class URL { toJSON(): string; } +/** The URL interface represents an object providing static methods used for + * creating object URLs. + * + * @category Web APIs + */ +declare var URL: { + readonly prototype: URL; + new (url: string | URL, base?: string | URL): URL; + canParse(url: string | URL, base?: string | URL): boolean; + createObjectURL(blob: Blob): string; + revokeObjectURL(url: string): void; +}; + /** @category Web APIs */ declare interface URLPatternInit { protocol?: string; @@ -265,9 +278,7 @@ declare interface URLPatternResult { * * @category Web APIs */ -declare class URLPattern { - constructor(input: URLPatternInput, baseURL?: string); - +declare interface URLPattern { /** * Test if the given input matches the stored pattern. * @@ -332,3 +343,38 @@ declare class URLPattern { /** The pattern string for the `hash`. */ readonly hash: string; } + +/** + * The URLPattern API provides a web platform primitive for matching URLs based + * on a convenient pattern syntax. + * + * The syntax is based on path-to-regexp. Wildcards, named capture groups, + * regular groups, and group modifiers are all supported. + * + * ```ts + * // Specify the pattern as structured data. + * const pattern = new URLPattern({ pathname: "/users/:user" }); + * const match = pattern.exec("https://blog.example.com/users/joe"); + * console.log(match.pathname.groups.user); // joe + * ``` + * + * ```ts + * // Specify a fully qualified string pattern. + * const pattern = new URLPattern("https://example.com/books/:id"); + * console.log(pattern.test("https://example.com/books/123")); // true + * console.log(pattern.test("https://deno.land/books/123")); // false + * ``` + * + * ```ts + * // Specify a relative string pattern with a base URL. + * const pattern = new URLPattern("/article/:id", "https://blog.example.com"); + * console.log(pattern.test("https://blog.example.com/article")); // false + * console.log(pattern.test("https://blog.example.com/article/123")); // true + * ``` + * + * @category Web APIs + */ +declare var URLPattern: { + readonly prototype: URLPattern; + new (input: URLPatternInput, baseURL?: string): URLPattern; +}; |