aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-19 10:24:59 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-19 10:24:59 -0400
commita7e7d546c70c604e986d5c772d842c47fb701eda (patch)
tree3096445ad292e3c96b113c544ea765d91064ce69 /ext/bg/js
parent0e80c0d5d03b51c56e72657a46c868c9a2c1137d (diff)
Add documentation
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/media-utility.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/ext/bg/js/media-utility.js b/ext/bg/js/media-utility.js
index fcbf9d37..1f93b2b4 100644
--- a/ext/bg/js/media-utility.js
+++ b/ext/bg/js/media-utility.js
@@ -15,12 +15,28 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/**
+ * mediaUtility is an object containing helper methods related to media processing.
+ */
const mediaUtility = (() => {
+ /**
+ * Gets the file extension of a file path. URL search queries and hash
+ * fragments are not handled.
+ * @param path The path to the file.
+ * @returns The file extension, including the '.', or an empty string
+ * if there is no file extension.
+ */
function getFileNameExtension(path) {
const match = /\.[^./\\]*$/.exec(path);
return match !== null ? match[0] : '';
}
+ /**
+ * Gets an image file's media type using a file path.
+ * @param path The path to the file.
+ * @returns The media type string if it can be determined from the file path,
+ * otherwise null.
+ */
function getImageMediaTypeFromFileName(path) {
switch (getFileNameExtension(path).toLowerCase()) {
case '.apng':
@@ -52,6 +68,13 @@ const mediaUtility = (() => {
}
}
+ /**
+ * Attempts to load an image using a base64 encoded content and a media type.
+ * @param mediaType The media type for the image content.
+ * @param content The binary content for the image, encoded in base64.
+ * @returns A Promise which resolves with an HTMLImageElement instance on
+ * successful load, otherwise an error is thrown.
+ */
function loadImageBase64(mediaType, content) {
return new Promise((resolve, reject) => {
const image = new Image();