base64.js (582B)
1 /* -*- Mode: js; js-indent-level: 2; -*- */ 2 /* 3 * Copyright 2011 Mozilla Foundation and contributors 4 * Licensed under the New BSD license. See LICENSE or: 5 * http://opensource.org/licenses/BSD-3-Clause 6 */ 7 8 const intToCharMap = 9 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""); 10 11 /** 12 * Encode an integer in the range of 0 to 63 to a single base 64 digit. 13 */ 14 exports.encode = function (number) { 15 if (0 <= number && number < intToCharMap.length) { 16 return intToCharMap[number]; 17 } 18 throw new TypeError("Must be between 0 and 63: " + number); 19 };