mirror of
https://github.com/LukeHagar/crossws.git
synced 2025-12-06 04:19:26 +00:00
docs: add destr tip for JSON parsing (#109)
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user