base64.js 582 B

12345678910111213141516171819
  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. const intToCharMap =
  8. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
  9. /**
  10. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  11. */
  12. exports.encode = function (number) {
  13. if (0 <= number && number < intToCharMap.length) {
  14. return intToCharMap[number];
  15. }
  16. throw new TypeError("Must be between 0 and 63: " + number);
  17. };