@metreeca/qest - v0.9.2
    Preparing search index...

    Function encodeQuery

    • Encodes a query as a URL-safe string.

      Serializes a Query object into a string representation suitable for transmission as a URL query string in GET requests. The output format can be selected based on readability, compactness, and compatibility requirements.

      If base is provided, converts absolute IRIs (matching isIRI(value, "absolute")) to root-relative IRIs using internalize, recursively throughout the query structure. Otherwise, performs plain serialization.

      Parameters

      Returns string

      The encoded query string, with internalized IRIs if base is provided

      If query is not a valid Query, opts.mode is not a supported format, or opts.base is not an absolute hierarchical IRI

      The "form" format always encodes to canonical form:

      • Operators use prefix notation (e.g., >=price=100)
      • String values are JSON double-quoted (e.g., name="widget")
      • Numbers, booleans, and null remain unquoted (JSON literals)
      • Sorting criteria are always numeric (e.g., ^price=1, ^name=-2)

      This ensures consistent, predictable output. The decoder accepts both canonical and shorthand forms (e.g., postfix operators like price>=100, unquoted strings like name=widget).

      encodeQuery(
      { "~name": "widget", ">=price": 50, "^price": 1, "#": 25 },
      { mode: "form" }
      );
      // → '~name=%22widget%22&%3E%3Dprice=50&%5Eprice=1&%23=25'