Skip to main content
Module

x/querystring/mod.js>pick

Parse and stringify URL query strings
Latest
function pick
import { pick } from "https://deno.land/x/querystring@v1.0.2/mod.js";

Pick query parameters from a URL.

Examples

Example 1

queryString.pick('https://foo.bar?foo=1&bar=2#hello', ['foo']);
//=> 'https://foo.bar?foo=1#hello'

queryString.pick('https://foo.bar?foo=1&bar=2#hello', (name, value) => value === 2, {parseNumbers: true});
//=> 'https://foo.bar?bar=2#hello'

Parameters

url: string
  • The URL containing the query parameters to pick.
keys: readonly string[]
  • The names of the query parameters to keep. All other query parameters will be removed from the URL.
optional
options: ParseOptions & StringifyOptions
  • A filter predicate that will be provided the name of each query parameter and its value. The parseNumbers and parseBooleans options also affect value.

Returns

string

The URL with the picked query parameters.

Parameters

url: string
filter: (key: string, value: string | boolean | number) => boolean
optional
options: { parseBooleans: true; parseNumbers: true; } & ParseOptions & StringifyOptions

Returns

string

Parameters

url: string
filter: (key: string, value: string | boolean) => boolean
optional
options: { parseBooleans: true; } & ParseOptions & StringifyOptions

Returns

string

Parameters

url: string
filter: (key: string, value: string | number) => boolean
optional
options: { parseNumbers: true; } & ParseOptions & StringifyOptions

Returns

string