MCPcopy Index your code
hub / github.com/mozilla/source-map / createSafeHandler

Function createSafeHandler

lib/util.js:177–199  ·  view source on GitHub ↗

* Make it easy to create small utilities that tweak a URL's path.

(cb)

Source from the content-addressed store, hash-verified

175 * Make it easy to create small utilities that tweak a URL's path.
176 */
177function createSafeHandler(cb) {
178 return input => {
179 const type = getURLType(input);
180 const base = buildSafeBase(input);
181 const url = new URL(input, base);
182
183 cb(url);
184
185 const result = url.toString();
186
187 if (type === "absolute") {
188 return result;
189 } else if (type === "scheme-relative") {
190 return result.slice(PROTOCOL.length);
191 } else if (type === "path-absolute") {
192 return result.slice(PROTOCOL_AND_HOST.length);
193 }
194
195 // This assumes that the callback will only change
196 // the path, search and hash values.
197 return computeRelativeURL(base, result);
198 };
199}
200
201function withBase(url, base) {
202 return new URL(url, base).toString();

Callers 1

util.jsFile · 0.85

Calls 4

getURLTypeFunction · 0.85
buildSafeBaseFunction · 0.85
computeRelativeURLFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…