RequestShortener.js 755 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const { contextify } = require("./util/identifier");
  7. class RequestShortener {
  8. /**
  9. * @param {string} dir the directory
  10. * @param {object=} associatedObjectForCache an object to which the cache will be attached
  11. */
  12. constructor(dir, associatedObjectForCache) {
  13. this.contextify = contextify.bindContextCache(
  14. dir,
  15. associatedObjectForCache
  16. );
  17. }
  18. /**
  19. * @param {string | undefined | null} request the request to shorten
  20. * @returns {string | undefined | null} the shortened request
  21. */
  22. shorten(request) {
  23. if (!request) {
  24. return request;
  25. }
  26. return this.contextify(request);
  27. }
  28. }
  29. module.exports = RequestShortener;