
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
bestbase64utf8
Advanced tools
The most standard, most cross-browser, most compact, and fastest possible btoa and atob solution for unicode strings with high code points. Made by AnonyCo with ❤️ from 🐕s.
Add the following HTML Code to your head:
<script src="https://www.dropbox.com/s/uo9kbpolhnat1cg/atobAndBtoaTogether.min.js?raw=1" type="text/javascript"></script>
If you know that nothing on the page loads until the DOMContentLoaded event, then you can switch to the much faster version below:
<script src="https://www.dropbox.com/s/uo9kbpolhnat1cg/atobAndBtoaTogether.min.js?raw=1" type="text/javascript" defer=""></script>
There are two separate API functions introduced by the library:
/**String*/ btoaUTF8(/**String*/ originalString, /**boolean*/ autoBOMit = false)
originalString
into valid base 64.autoBOMit
determines whether to append a BOM on to the end of the string. Only use this when the base64 is to be used as a data URI link. If you have no idea what this means and are confused, then simply ignore this option and it should not give you any problems./**String*/ atobUTF8(/**String*/ encodedBase64String, /**boolean*/ keepBOM = false)
encodedBase64String
into its original UTF8 binary counterpart.keepBOM
will keep the BOM of the string. Use this option if you are certain that the original UTF8 string was raw binary data. Keep this option false if you used the autoBOMit
option when encoding the string.I would assume that one might want it base64 encoded in a more standard way than other solutions that attempt to address this problem. This "standard" way is naturally interpretable by the browser such that you can use the base64 in a data URI. Please visit this data URI here to see a demonstration: data:text/plain;base64,4pi44pi54pi64pi74pi84pi+4pi/
(copy the data uri, open a new tab, paste the data URI into the address bar, then press enter to go to the page). As you can see, despite the fact that it is a base64-encoded URL, the browser is still able to recognize the high code points and decode them properly. Thus, this demonstration proves that this is the best way to go because it is the most W3C standard. Then, to decode the base64 data, either HTTP get the data as a data URI or use the function below. The advantage of being more standard is that this encoder and this decoder are more widely applicable because they can be used as a valid URL that displays correctly.
In addition to being very standardized, the above code snippets are also very fast. Instead of an indirect chain of succession where the data has to be converted several times between various forms, the above code snippet is as direct as performantly possible. It uses only one simple fast String.prototype.replace
call to process the data when encoding, and only one to decode the data when decoding. Another plus is that (especially for big strings), String.prototype.replace
allows the browser to automatically handle the underlying memory management of resizing the string, leading a significant performance boost especially in evergreen browsers like Chrome and Firefox that heavily optimize String.prototype.replace
. Finally, the icing on the cake is that for you latin script exclūsīvō users, strings which don't contain any code points above 0x7f are extra fast to process because the string remains unmodified by the replacement algorithm.
(see also https://stackoverflow.com/a/53433503/5601591)
(see also The MDN Page Base64_encoding_and_decoding)
Simply drop the file atobAndBtoaTogether.node.js
into the same folder as your Javascript node file. Then, add the following to the Javascript to the node file:
var AtobAndBtoaTogether = require("./atobAndBtoaTogether.node.js");
Then, here is the node API:
/**String*/ AtobAndBtoaTogether.btoaUTF8(/**String*/ originalString, /**boolean*/ autoBOMit = false)
originalString
into valid base 64.autoBOMit
determines whether to append a BOM on to the end of the string. Only use this when the base64 is to be used as a data URI link. If you have no idea what this means and are confused, then simply ignore this option and it should not give you any problems./**String*/ AtobAndBtoaTogether.atobUTF8(/**String*/ encodedBase64String, /**boolean*/ keepBOM = false)
encodedBase64String
into its original UTF8 binary counterpart.keepBOM
will keep the BOM of the string. Use this option if you are certain that the original UTF8 string was raw binary data. Keep this option false if you used the autoBOMit
option when encoding the string.Enjoy!
FAQs
The most standard, most cross-browser, most compact, and fastest possible btoa and atob solution for unicode strings with high code points. Made by AnonyCo with ❤️ from 🐕s.
We found that bestbase64utf8 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.