MCPcopy Index your code
hub / github.com/nodejs/node / urlFormat

Function urlFormat

lib/url.js:575–615  ·  view source on GitHub ↗
(urlObject, options)

Source from the content-addressed store, hash-verified

573
574// Format a parsed object into a url string
575function urlFormat(urlObject, options) {
576 // Ensure it's an object, and not a string url.
577 // If it's an object, this is a no-op.
578 // this way, you can call urlParse() on strings
579 // to clean up potentially wonky urls.
580 if (typeof urlObject === 'string') {
581 urlObject = urlParse(urlObject);
582 } else if (typeof urlObject !== 'object' || urlObject === null) {
583 throw new ERR_INVALID_ARG_TYPE('urlObject',
584 ['Object', 'string'], urlObject);
585 } else if (urlObject instanceof URL) {
586 let fragment = true;
587 let unicode = false;
588 let search = true;
589 let auth = true;
590
591 if (options) {
592 validateObject(options, 'options');
593
594 if (options.fragment != null) {
595 fragment = Boolean(options.fragment);
596 }
597
598 if (options.unicode != null) {
599 unicode = Boolean(options.unicode);
600 }
601
602 if (options.search != null) {
603 search = Boolean(options.search);
604 }
605
606 if (options.auth != null) {
607 auth = Boolean(options.auth);
608 }
609 }
610
611 return bindingUrl.format(urlObject.href, fragment, unicode, search, auth);
612 }
613
614 return Url.prototype.format.call(urlObject);
615}
616
617// These characters do not need escaping:
618// ! - . _ ~

Callers

nothing calls this directly

Calls 3

urlParseFunction · 0.85
formatMethod · 0.65
callMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…