docs: add destr tip for JSON parsing (#109)

This commit is contained in:
Sandro Circi
2025-01-21 22:32:40 +01:00
committed by GitHub
parent bef0f4f372
commit 14b4f6b132

View File

@@ -43,6 +43,15 @@ If raw data is in any other format, it will be automatically converted or decode
Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
> [!TIP]
> You can optionally use [`unjs/destr`](https://github.com/unjs/destr) to safely parse the message object.
>
> It does not throw an error if the input is not valid JSON but falls back to text and also removes any fields that could potentially cause prototype pollution vulnerabilities.
>
> ```ts
> const data = destr(await message.text());
> ```
### `message.uint8Array()`
Get data as [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.