@grafctory/qest - v0.16.0
    Preparing search index...

    Function encodeCriteria

    • Encodes criteria as a URL-safe string.

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

      Note

      The encoder always produces canonical form:

      • Operators use prefix notation (for example, ~name=widget), except for the postfix aliases: disjunctive matching omits its ? (category=home), and <= and >= follow the expression (price>=100)
      • The empty expression keeps the prefix notation (for example, ?=value, >==100), which is unambiguous there
      • String values are written bare (for example, name=widget)
      • Strings that would read back as another value are JSON double-quoted (for example, code="123", flag="true", email="user@example")
      • 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 also accepts prefix operators (>=price=100), an explicit ? (?name=widget) and redundant quotes (name="widget"), so older or hand-written URLs still decode.

      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

      • criteria: Criteria

        The criteria 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 the base namespace IRI (base:/#).

        • 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 criteria string with internalised IRIs

      TypeError If base is not a hierarchical IRI

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