UNPKG

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