Base85.mjs 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Utils from "../Utils.mjs";
  2. /**
  3. * Base85 resources.
  4. *
  5. * @author PenguinGeorge [george@penguingeorge.com]
  6. * @copyright Crown Copyright 2018
  7. * @license Apache-2.0
  8. */
  9. /**
  10. * Base85 alphabet options.
  11. */
  12. export const ALPHABET_OPTIONS = [
  13. {
  14. name: "Standard",
  15. value: "!-u",
  16. },
  17. {
  18. name: "Z85 (ZeroMQ)",
  19. value: "0-9a-zA-Z.\\-:+=^!/*?&<>()[]{}@%$#",
  20. },
  21. {
  22. name: "IPv6",
  23. value: "0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~",
  24. }
  25. ];
  26. /**
  27. * Returns the name of the alphabet, when given the alphabet.
  28. *
  29. * @param {string} alphabet
  30. * @returns {string}
  31. */
  32. export function alphabetName(alphabet) {
  33. alphabet = escape(alphabet);
  34. let name;
  35. ALPHABET_OPTIONS.forEach(function(a) {
  36. const expanded = Utils.expandAlphRange(a.value).join("");
  37. if (alphabet === escape(expanded)) name = a.name;
  38. });
  39. return name;
  40. }