Last active
April 27, 2022 13:30
-
-
Save exsesx/90b4a77ce80a3d1218dffdbab1f7c675 to your computer and use it in GitHub Desktop.
Revisions
-
exsesx revised this gist
Apr 27, 2022 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,4 +8,6 @@ Tested with Node.js LTS (16 at the time of the gist creation). buildUrl('http://example.com', 'a', 'b', 'c').toString() // http://example.com/a/b/c ``` > Note that the function returns a [URL](https://nodejs.org/api/url.html) object, not a string. > This gist is mostly inspired by a post on [StackOverflow](https://stackoverflow.com/questions/16301503/can-i-use-requirepath-join-to-safely-concatenate-urls). -
exsesx revised this gist
Apr 27, 2022 . 1 changed file with 3 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,24 +5,7 @@ An easy solution to a common problem. Tested with Node.js LTS (16 at the time of the gist creation). ```javascript buildUrl('http://example.com', 'a', 'b', 'c').toString() // http://example.com/a/b/c ``` > Note that the function returns a [URL](https://nodejs.org/api/url.html) object, not a string. -
exsesx revised this gist
Apr 27, 2022 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ # Usage An easy solution to a common problem. Tested with Node.js LTS (16 at the time of the gist creation). ```javascript const result = buildUrl('http://example.com', 'a', 'b', 'c') /* URL { @@ -23,4 +23,6 @@ URL { hash: '' } */ result.toString() // http://example.com/a/b/c ``` -
exsesx revised this gist
Apr 27, 2022 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,8 @@ const result = buildUrl('http://example.com', 'a', 'b', 'c') result.toString() // http://example.com/a/b/c /* URL { href: 'http://example.com/a/b/c', -
exsesx revised this gist
Apr 27, 2022 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,9 @@ ```javascript const result = buildUrl('http://example.com', 'a', 'b', 'c') result.toString() // http://example.com/a/b/c /* URL { href: 'http://example.com/a/b/c', origin: 'http://example.com', @@ -19,8 +20,5 @@ URL { searchParams: URLSearchParams {}, hash: '' } */ ``` -
exsesx renamed this gist
Apr 27, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
exsesx renamed this gist
Apr 27, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
exsesx renamed this gist
Apr 27, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
exsesx created this gist
Apr 27, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ # Usage ```javascript const result = buildUrl('http://example.com', 'a', 'b', 'c') /* URL { href: 'http://example.com/a/b/c', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/a/b/c', search: '', searchParams: URLSearchParams {}, hash: '' } */ result.toString() // http://example.com/a/b/c ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ const path = require('path'); function buildUrl(base, ...inputs) { return new URL(path.posix.join(...inputs), base); } module.exports = { buildUrl, }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ import path from 'path'; export function buildUrl(base, ...inputs) { return new URL(path.posix.join(...inputs), base); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ import path from 'path'; export function buildUrl(base: string, ...inputs: string[]): URL { return new URL(path.posix.join(...inputs), base); }