utils.js 579 B

1234567891011121314151617181920212223
  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. };