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

    Function encodeResource

    • Encodes a resource state as a JSON string.

      Serialises a Resource into a JSON string, recursively internalising absolute IRIs against the provided base.

      Vacuous values are never surfaced: an empty array, nested Resource, or Dictionary, at any nesting depth, causes the owning field to be omitted, while an empty object appearing as an array element, or an empty array standing as a tag's value in a Dictionary, is dropped from its container. Omission cascades, so a field left empty once its own contents are omitted is omitted in turn, and a resource left with no content at all encodes as an empty document.

      Parameters

      • resource: Resource

        The resource state 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 app namespace IRI (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 JSON string with internalised IRIs and empty values omitted

      TypeError If base is not a hierarchical IRI

      encodeResource(
      { id: "https://example.com/products/42", name: "Widget", price: 29.99, tags: [] },
      { base: "https://example.com/" }
      );
      // → '{"id":"/products/42","name":"Widget","price":29.99}'