You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
579 B

  1. "use strict";
  2. const { percentDecode } = require("whatwg-url");
  3. const { atob } = require("abab");
  4. exports.stripLeadingAndTrailingASCIIWhitespace = string => {
  5. return string.replace(/^[ \t\n\f\r]+/, "").replace(/[ \t\n\f\r]+$/, "");
  6. };
  7. exports.stringPercentDecode = input => {
  8. return percentDecode(Buffer.from(input, "utf-8"));
  9. };
  10. exports.isomorphicDecode = input => {
  11. return input.toString("binary");
  12. };
  13. exports.forgivingBase64Decode = data => {
  14. const asString = atob(data);
  15. if (asString === null) {
  16. return null;
  17. }
  18. return Buffer.from(asString, "binary");
  19. };