Skip to content

Commit

Permalink
Add task 'parse URL' for breaking for hard to read URL's
Browse files Browse the repository at this point in the history
  • Loading branch information
haukurh committed Jul 19, 2024
1 parent 64df22b commit 49bfe77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.4] - 2024-07-19

### Added

- Add task 'parse URL' for breaking for hard to read URL's

## [2.0.3] - 2023-06-05

### Added
Expand Down
20 changes: 20 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ <h1>Online tools</h1>
<aside>
<form id="tasks">
<fieldset>
<label><input type="radio" name="task" value="url2json" required> parse URL</label>
<label><input type="radio" name="task" value="urlEncode" required> URL encode</label>
<label><input type="radio" name="task" value="urlDecode" required> URL decode</label>
<label><input type="radio" name="task" value="base64Encode" required> base64 encode</label>
Expand Down Expand Up @@ -263,7 +264,26 @@ <h1>Online tools</h1>
return Object.fromEntries(data);
};

function parseUrl(url) {
const u = new URL(url);
const params = [];
for (const [key, value] of u.searchParams) {
params.push({ [key]: value });
}
return {
scheme: u.protocol,
username: u.username,
password: u.password,
host: u.hostname,
port: u.port,
path: u.pathname,
query: params,
fragment: u.hash,
};
}

const tasks = {
url2json: (data) => JSON.stringify(parseUrl(data), null, 2),
urlEncode: (data) => encodeURIComponent(data),
urlDecode: (data) => decodeURIComponent(data),
base64Encode: (data) => window.btoa(data),
Expand Down

0 comments on commit 49bfe77

Please sign in to comment.