MCPcopy
hub / github.com/vercel/next.js / createSafeHandler

Function createSafeHandler

packages/next/src/compiled/source-map08/source-map.js:2541–2563  ·  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

2539 * Make it easy to create small utilities that tweak a URL's path.
2540 */
2541function createSafeHandler(cb) {
2542 return input => {
2543 const type = getURLType(input);
2544 const base = buildSafeBase(input);
2545 const url = new URL(input, base);
2546
2547 cb(url);
2548
2549 const result = url.toString();
2550
2551 if (type === "absolute") {
2552 return result;
2553 } else if (type === "scheme-relative") {
2554 return result.slice(PROTOCOL.length);
2555 } else if (type === "path-absolute") {
2556 return result.slice(PROTOCOL_AND_HOST.length);
2557 }
2558
2559 // This assumes that the callback will only change
2560 // the path, search and hash values.
2561 return computeRelativeURL(base, result);
2562 };
2563}
2564
2565function withBase(url, base) {
2566 return new URL(url, base).toString();

Callers 1

source-map.jsFile · 0.85

Calls 6

buildSafeBaseFunction · 0.85
computeRelativeURLFunction · 0.85
getURLTypeFunction · 0.70
cbFunction · 0.50
toStringMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…