Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
[feat] add function to parse URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Sep 8, 2019
1 parent 2f71320 commit 611f1d6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/strings/parseURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Return all parameters of an URL.
* @param url
* @returns {{hostname: *, protocol: *, port: *, params: *}}
*/
export function parseURL (url) {
if (typeof url !== 'string') {
throw TypeError('Parameter must be a string.')
}

url = new URL(url)

return {
hostname: url.hostname,
port: url.port,
protocol: url.protocol.replace(':', ''),
params: url.searchParams.entries()
}
}

0 comments on commit 611f1d6

Please sign in to comment.