Created
May 3, 2023 12:42
-
-
Save stoneparker/eba4132fe325aa316d0b4da4b480d1b2 to your computer and use it in GitHub Desktop.
Snippet to parse stringified messages to original type, when it's unknow. Useful to pub/sub channels that only allow string messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseMessage(msg) { | |
try { | |
return JSON.parse(msg); | |
} catch (e) { | |
return msg; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment