MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / cleanFileName

Function cleanFileName

example/tests/gm_xhr_test.js:330–363  ·  view source on GitHub ↗
(file, options)

Source from the content-addressed store, hash-verified

328 }
329
330 function cleanFileName(file, options) {
331 let s = String(file);
332
333 if (options.stripQuery) {
334 s = s.replace(/[?#].*$/, "");
335 }
336
337 if (options.dropExtensionUuid) {
338 s = s.replace(
339 /^(?:moz|chrome)-extension:\/\/[^/]+\//,
340 "extension://"
341 );
342 }
343
344 let parts = s.split("/");
345
346 if (options.pathSegments > 0) {
347 parts = parts.slice(-options.pathSegments);
348 }
349
350 if (options.decode) {
351 parts = parts.map(part => {
352 try {
353 return decodeURIComponent(part);
354 } catch {
355 return part;
356 }
357 });
358 }
359
360 s = parts.join("/");
361
362 return truncateMiddle(s, options.maxUrlLength);
363 }
364
365 function truncateMiddle(value, max) {
366 const str = String(value);

Callers 1

prettyStackFunction · 0.70

Calls 2

truncateMiddleFunction · 0.85
sliceMethod · 0.45

Tested by

no test coverage detected