Class QueryBuilder

Hierarchy

  • URLSearchParams
    • QueryBuilder

Constructors

  • Parameters

    • Optional init: string | URLSearchParams | Record<string, string | readonly string[]> | readonly [string, string][] | Iterable<[string, string]>

    Returns QueryBuilder

Properties

size: number

The total number of parameter entries.

Since

v18.16.0

Methods

  • Returns URLSearchParamsIterator<[string, string]>

  • Append a new name-value pair to the query string.

    Parameters

    • name: string
    • value: string

    Returns void

  • If value is provided, removes all name-value pairs where name is name and value is value.

    If value is not provided, removes all name-value pairs whose name is name.

    Parameters

    • name: string
    • Optional value: string

    Returns void

  • Returns an ES6 Iterator over each of the name-value pairs in the query. Each item of the iterator is a JavaScript Array. The first item of the Array is the name, the second item of the Array is the value.

    Alias for urlSearchParams[@@iterator]().

    Returns URLSearchParamsIterator<[string, string]>

  • Iterates over each name-value pair in the query and invokes the given function.

    const myURL = new URL('https://example.org/?a=b&#x26;c=d');
    myURL.searchParams.forEach((value, name, searchParams) => {
    console.log(name, value, myURL.searchParams === searchParams);
    });
    // Prints:
    // a b true
    // c d true

    Type Parameters

    Parameters

    • fn: ((this, value, name, searchParams) => void)

      Invoked for each name-value pair in the query

        • (this, value, name, searchParams): void
        • Parameters

          • this: TThis
          • value: string
          • name: string
          • searchParams: URLSearchParams

          Returns void

    • Optional thisArg: TThis

      To be used as this value for when fn is called

    Returns void

  • Returns the value of the first name-value pair whose name is name. If there are no such pairs, null is returned.

    Parameters

    • name: string

    Returns null | string

    or null if there is no name-value pair with the given name.

  • Returns the values of all name-value pairs whose name is name. If there are no such pairs, an empty array is returned.

    Parameters

    • name: string

    Returns string[]

  • Checks if the URLSearchParams object contains key-value pair(s) based on name and an optional value argument.

    If value is provided, returns true when name-value pair with same name and value exists.

    If value is not provided, returns true if there is at least one name-value pair whose name is name.

    Parameters

    • name: string
    • Optional value: string

    Returns boolean

  • Returns an ES6 Iterator over the names of each name-value pair.

    const params = new URLSearchParams('foo=bar&#x26;foo=baz');
    for (const name of params.keys()) {
    console.log(name);
    }
    // Prints:
    // foo
    // foo

    Returns URLSearchParamsIterator<string>

  • Parameters

    • name: string
    • value: unknown

    Returns void

  • Sort all existing name-value pairs in-place by their names. Sorting is done with a stable sorting algorithm, so relative order between name-value pairs with the same name is preserved.

    This method can be used, in particular, to increase cache hits.

    const params = new URLSearchParams('query[]=abc&#x26;type=search&#x26;query[]=123');
    params.sort();
    console.log(params.toString());
    // Prints query%5B%5D=abc&#x26;query%5B%5D=123&#x26;type=search

    Returns void

    Since

    v7.7.0, v6.13.0

  • Returns the search parameters serialized as a string, with characters percent-encoded where necessary.

    Returns string

  • Returns an ES6 Iterator over the values of each name-value pair.

    Returns URLSearchParamsIterator<string>