Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace qs

Index

Type aliases

Stringifiable

Stringifiable: string | boolean | number | null | undefined

StringifiableRecord

StringifiableRecord: Record<string, Stringifiable | readonly Stringifiable[]>

Functions

exclude

  • exclude(url: string, keys: readonly string[], options?: ParseOptions & StringifyOptions): string
  • exclude(url: string, filter: (key: string, value: string | boolean | number) => boolean, options?: { parseBooleans: true; parseNumbers: true } & ParseOptions & StringifyOptions): string
  • exclude(url: string, filter: (key: string, value: string | boolean) => boolean, options?: { parseBooleans: true } & ParseOptions & StringifyOptions): string
  • exclude(url: string, filter: (key: string, value: string | number) => boolean, options?: { parseNumbers: true } & ParseOptions & StringifyOptions): string
  • Exclude query parameters from a URL. Like .pick() but reversed.

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

    Parameters

    • url: string

      The URL containing the query parameters to exclude.

    • keys: readonly string[]

      The names of the query parameters to remove. All other query parameters will remain in the URL.

    • Optional options: ParseOptions & StringifyOptions

    Returns string

    The URL without the excluded the query parameters.

  • Parameters

    • url: string
    • filter: (key: string, value: string | boolean | number) => boolean
        • (key: string, value: string | boolean | number): boolean
        • Parameters

          • key: string
          • value: string | boolean | number

          Returns boolean

    • Optional options: { parseBooleans: true; parseNumbers: true } & ParseOptions & StringifyOptions

    Returns string

  • Parameters

    • url: string
    • filter: (key: string, value: string | boolean) => boolean
        • (key: string, value: string | boolean): boolean
        • Parameters

          • key: string
          • value: string | boolean

          Returns boolean

    • Optional options: { parseBooleans: true } & ParseOptions & StringifyOptions

    Returns string

  • Parameters

    • url: string
    • filter: (key: string, value: string | number) => boolean
        • (key: string, value: string | number): boolean
        • Parameters

          • key: string
          • value: string | number

          Returns boolean

    • Optional options: { parseNumbers: true } & ParseOptions & StringifyOptions

    Returns string

extract

  • extract(url: string): string
  • Extract a query string from a URL that can be passed into .parse().

    Note: This behaviour can be changed with the skipNull option.

    Parameters

    • url: string

    Returns string

parse

  • Parse a query string into an object. Leading ? or # are ignored, so you can pass location.search or location.hash directly.

    The returned object is created with Object.create(null) and thus does not have a prototype.

    Parameters

    • query: string

      The query string to parse.

    • options: { parseBooleans: true; parseNumbers: true } & ParseOptions

    Returns ParsedQuery<string | boolean | number>

  • Parameters

    • query: string
    • options: { parseBooleans: true } & ParseOptions

    Returns ParsedQuery<string | boolean>

  • Parameters

    • query: string
    • options: { parseNumbers: true } & ParseOptions

    Returns ParsedQuery<string | number>

  • Parameters

    Returns ParsedQuery

parseUrl

  • Extract the URL and the query string as an object.

    If the parseFragmentIdentifier option is true, the object will also contain a fragmentIdentifier property.

    example
    import queryString = require('query-string');
    
    queryString.parseUrl('https://foo.bar?foo=bar');
    //=> {url: 'https://foo.bar', query: {foo: 'bar'}}
    
    queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
    //=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
    

    Parameters

    • url: string

      The URL to parse.

    • Optional options: ParseOptions

    Returns ParsedUrl

pick

  • pick(url: string, keys: readonly string[], options?: ParseOptions & StringifyOptions): string
  • pick(url: string, filter: (key: string, value: string | boolean | number) => boolean, options?: { parseBooleans: true; parseNumbers: true } & ParseOptions & StringifyOptions): string
  • pick(url: string, filter: (key: string, value: string | boolean) => boolean, options?: { parseBooleans: true } & ParseOptions & StringifyOptions): string
  • pick(url: string, filter: (key: string, value: string | number) => boolean, options?: { parseNumbers: true } & ParseOptions & StringifyOptions): string
  • Pick query parameters from a URL.

    example
    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

    Returns string

    The URL with the picked query parameters.

  • Parameters

    • url: string
    • filter: (key: string, value: string | boolean | number) => boolean
        • (key: string, value: string | boolean | number): boolean
        • Parameters

          • key: string
          • value: string | boolean | number

          Returns boolean

    • Optional options: { parseBooleans: true; parseNumbers: true } & ParseOptions & StringifyOptions

    Returns string

  • Parameters

    • url: string
    • filter: (key: string, value: string | boolean) => boolean
        • (key: string, value: string | boolean): boolean
        • Parameters

          • key: string
          • value: string | boolean

          Returns boolean

    • Optional options: { parseBooleans: true } & ParseOptions & StringifyOptions

    Returns string

  • Parameters

    • url: string
    • filter: (key: string, value: string | number) => boolean
        • (key: string, value: string | number): boolean
        • Parameters

          • key: string
          • value: string | number

          Returns boolean

    • Optional options: { parseNumbers: true } & ParseOptions & StringifyOptions

    Returns string

stringify

  • Stringify an object into a query string and sort the keys.

    Parameters

    Returns string

stringifyUrl

  • Stringify an object into a URL with a query string and sorting the keys. The inverse of .parseUrl()

    Query items in the query property overrides queries in the url property.

    The fragmentIdentifier property overrides the fragment identifier in the url property.

    example
    queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}});
    //=> 'https://foo.bar?foo=bar'
    
    queryString.stringifyUrl({url: 'https://foo.bar?foo=baz', query: {foo: 'bar'}});
    //=> 'https://foo.bar?foo=bar'
    
    queryString.stringifyUrl({
    url: 'https://foo.bar',
    query: {
    top: 'foo'
    },
    fragmentIdentifier: 'bar'
    });
    //=> 'https://foo.bar?top=foo#bar'
    

    Parameters

    Returns string