bare-url 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -389,3 +389,62 @@ exports.pathToFileURL = function pathToFileURL(pathname) {
389
389
 
390
390
  return new URL('file:' + resolved)
391
391
  }
392
+
393
+ exports.format = function format(parts) {
394
+ const {
395
+ protocol,
396
+ auth,
397
+ host,
398
+ hostname,
399
+ port,
400
+ pathname,
401
+ search,
402
+ query,
403
+ hash,
404
+ slashes
405
+ } = parts
406
+
407
+ let result = ''
408
+
409
+ if (typeof protocol === 'string') {
410
+ result += protocol
411
+
412
+ if (protocol[protocol.length - 1] !== ':') {
413
+ result += ':'
414
+ }
415
+
416
+ if (slashes === true || /https?|ftp|gopher|file/.test(protocol)) {
417
+ result += '//'
418
+ }
419
+ }
420
+
421
+ if (typeof auth === 'string') {
422
+ if (host || hostname) result += auth + '@'
423
+ }
424
+
425
+ if (typeof host === 'string') result += host
426
+ else {
427
+ result += hostname
428
+
429
+ if (port) result += ':' + port
430
+ }
431
+
432
+ if (typeof pathname === 'string' && pathname !== '') {
433
+ if (pathname[0] !== '/') result += '/'
434
+ result += pathname
435
+ }
436
+
437
+ if (typeof search === 'string') {
438
+ if (search[0] !== '?') result += '?'
439
+ result += search
440
+ } else if (typeof query === 'object' && query !== null) {
441
+ result += '?' + new URLSearchParams(query)
442
+ }
443
+
444
+ if (typeof hash === 'string') {
445
+ if (hash[0] !== '#') result += '#'
446
+ result += hash
447
+ }
448
+
449
+ return result
450
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-url",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "WHATWG URL implementation for JavaScript",
5
5
  "exports": {
6
6
  "./package": "./package.json",
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file