MCPcopy Create free account
hub / github.com/microsoft/SandDance / base64clean

Function base64clean

docs/app/js/sanddance-app.js:113963–113973  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

113961// ================
113962var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
113963function base64clean(str) {
113964 // Node takes equal signs as end of the Base64 encoding
113965 str = str.split("=")[0];
113966 // Node strips out invalid characters like \n and \t from the string, base64-js does not
113967 str = str.trim().replace(INVALID_BASE64_RE, "");
113968 // Node converts strings with length < 2 to ''
113969 if (str.length < 2) return "";
113970 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
113971 while(str.length % 4 !== 0)str = str + "=";
113972 return str;
113973}
113974function utf8ToBytes(string, units) {
113975 units = units || Infinity;
113976 var codePoint;

Callers 1

base64ToBytesFunction · 0.70

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected