RequestShortener.js 870 B

123456789101112131415161718192021222324252627282930313233343536
  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. /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
  8. class RequestShortener {
  9. /**
  10. * @param {string} dir the directory
  11. * @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached
  12. */
  13. constructor(dir, associatedObjectForCache) {
  14. this.contextify = contextify.bindContextCache(
  15. dir,
  16. associatedObjectForCache
  17. );
  18. }
  19. /**
  20. * @param {string | undefined | null} request the request to shorten
  21. * @returns {string | undefined | null} the shortened request
  22. */
  23. shorten(request) {
  24. if (!request) {
  25. return request;
  26. }
  27. return this.contextify(request);
  28. }
  29. }
  30. module.exports = RequestShortener;