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

    Function encodeSelection

    • Encodes a selection as a URL-safe string.

      Serialises a Selection into an application/x-www-form-urlencoded string, recursively internalising absolute IRIs against the provided base; see Selection Serialisation for the wire format.

      Note

      The encoder always produces canonical form:

      • Operators use prefix notation (for example, >=price=100)
      • String values are JSON double-quoted (for example, name="widget")
      • Numbers, booleans, and null remain unquoted (JSON literals)
      • Sorting criteria are always numeric (for example, ^price=1, ^name=-2)
      • A Dictionary entry is flattened using a single postfix @tag suffix (for example, "text"@en)

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

      Warning

      The codec treats the @tag suffix as an opaque key and assigns it no semantic meaning. Consumers are responsible for interpreting the resulting Dictionary using schema-based information.

      Parameters

      • selection: Selection

        The selection to encode

      • options: EncoderOpts = {}

        Encoding options

        Configuration options for encoding operations.

        • Optional Readonlybase?: IRI

          Base IRI for IRI internalisation (must be absolute and hierarchical).

          Converts absolute IRIs to internal (root-relative) form.

          If omitted, IRIs are internalised against app.

        • Optional Readonlyindent?: boolean | number

          Indentation level for pretty-printing encoded output.

          • When true, uses default indentation
          • When a positive number, indents with that many spaces
          • When false or a number less than or equal to 0, disables indentation

          If omitted, output is not indented.

      Returns string

      The encoded selection string with internalised IRIs

      TypeError If base is not a hierarchical IRI

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