/* ------------------------------------------------------------------------------------
- base64 - MIT License - Hexagon <github.com/Hexagon>
+ base64 - MIT License - Hexagon <hexagon@56k.guru>
------------------------------------------------------------------------------------
License:
- Copyright (c) 2021 Hexagon <github.com/Hexagon>
+ Copyright (c) 2021 Hexagon <hexagon@56k.guru>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -252,10 +252,11 @@
* @public
*
* @param {string} str - Base64 encoded string to be decoded
+ * @param {boolean} [urlMode] - If set to true, URL mode string will be expected
* @returns {string} - Decoded string
*/
base64.toString = (str, urlMode) => {
- return Buffer.from(base64.toArrayBuffer(str, urlMode)).toString();
+ return new TextDecoder().decode(base64.toArrayBuffer(str, urlMode));
};
/**
@@ -263,10 +264,11 @@
* @public
*
* @param {string} str - String to be converted to base64
+ * @param {boolean} [urlMode] - If set to true, URL mode string will be returned
* @returns {string} - Base64 encoded string
*/
base64.fromString = (str, urlMode) => {
- return base64.fromArrayBuffer(Buffer.from(str), urlMode);
+ return base64.fromArrayBuffer(new TextEncoder().encode(str), urlMode);
};
export default base64;
diff --git a/docs/index.html b/docs/index.html
index 7cb1b2f..1bb05ee 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -130,8 +130,8 @@
@hexagon/base64
Base64 and base64url to string or arraybuffer, and back. Works in Node, Deno or browser.
+
+