BC-DCBOR-Parse TypeScript Library - v1.0.0-alpha.20
    Preparing search index...

    Function parseDcborItem

    • Parses a dCBOR item from a string input.

      This function takes a string slice containing a dCBOR diagnostic notation encoded value and attempts to parse it into a Cbor object. If the input contains extra tokens after a valid item, an error is returned.

      Parameters

      • src: string

        A string containing the dCBOR-encoded data.

      Returns ParseResult<Cbor>

      Ok(Cbor) if parsing is successful and the input contains exactly one valid dCBOR item, which itself might be an atomic value like a number or string, or a complex value like an array or map. Err(ParseError) if parsing fails or if extra tokens are found after the item.

      const result = parseDcborItem("[1, 2, 3]");
      if (result.ok) {
      console.log(result.value.toDiagnostic()); // "[1, 2, 3]"
      }