-
-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add encode
and decode
expression functions
#2842
Conversation
Any thoughts on the names of these functions? I think 'fromHex' and 'toHex' can easily be mixed up with a numerical conversion. |
@dnmeid you make good points there. |
Number literals (0x10, 0b11) are already converted automatically. I was looking for descriptive, yet brief, function names. This was a 'fun' to get working:
(A language I used in the '80s had built-in
These have been deprecated for a while. |
@istnv don't get me wrong, I'm not talking about implementation, just about the names. |
I am also trying to keep the names similar since they are nearly identical functions. There is definitely a need for a better input widget. Since we now have a couple of reserved namespaces ( |
Another idea. Basically expose decode(str, enc) Decodes an string from the passed encoding ('hex','base64') eg encode(str, enc) Encodes a string to the passed encoding ('hex','base64') eg |
Since 'hex' is used to pass binary data, I've set @Julusian
|
If enc is missing or invalid, I suggest to go with the same default as js does: utf8 |
For binary messages, I have encountered 'utf8' and 'ascii' breaking values above 0x7f. A default of 'latin1' will cause less confusion since that will probably be the majority of uses. If someone really wants 'utf8', they specify that as the encoding. |
@Julusian |
@Julusian I don't have write access. I'm OK with that, but cannot merge the PR myself. |
encode
and decode
expression functions
Adds string encode/decode functions.
fromHex(val)
Decodes a Hex encoded string.
eg
fromHex("436f6d70616e696f6e")
gives"Companion"
toHex(val)
Hex encodes a string.
eg
toHex("Companion")
gives"436f6d70616e696f6e"
from64(val)
Decodes a Base64 encoded string.
eg
from64("Q29tcGFuaW9uCg=="")
gives"Companion"
to64(val)
Encodes a string to Base64.
eg
to64("Companion")
gives"Q29tcGFuaW9uCg=="