From 152284e443b4601ed45aa2e2596ce6feb1cca365 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 11 Sep 2019 15:39:22 +0200 Subject: [PATCH] implement util.bake and polyfill btoa and atob --- www/common/common-util.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/www/common/common-util.js b/www/common/common-util.js index fe62d42ba..020f3a7b7 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -1,6 +1,18 @@ (function (window) { var Util = {}; + // polyfill for atob in case you're using this from node... + window.atob = window.atob || function (str) { return Buffer.from(str, 'base64').toString('binary'); }; // jshint ignore:line + window.btoa = window.btoa || function (str) { return new Buffer(str, 'binary').toString('base64'); }; // jshint ignore:line + + Util.bake = function (f, args) { + if (typeof(args) === 'undefined') { args = []; } + if (!Array.isArray(args)) { args = [args]; } + return function () { + return f.apply(null, args); + }; + }; + Util.both = function (pre, post) { if (typeof(post) !== 'function') { post = function (x) { return x; }; } return function () { @@ -78,7 +90,7 @@ Util.base64ToHex = function (b64String) { var hexArray = []; - atob(b64String.replace(/-/g, '/')).split("").forEach(function(e){ + window.atob(b64String.replace(/-/g, '/')).split("").forEach(function(e){ var h = e.charCodeAt(0).toString(16); if (h.length === 1) { h = "0"+h; } hexArray.push(h);