-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chore) Refactor the code around parsed and entry (#52)
* (chore) Refactor the code around parsed and entry This commit changes a couple of things to make both apis be more similar. There was an error in parsed where toSchemeLess would return a protocol-less version. This is fixed. toRelative does not make sense without a 'base' url (relative to what?). node's path.relative requires 2 params. So it is now deprecated 4 new functions, across 3 new files were created to avoid code dup. 2 of them are exposed in the barrel file, since they work on strings. The other two are not since they require a valid URL object, which is not validated, hence, not exposed. Some improvement, IMHO, to the docs. * (chore) Add cs * Fix typo Co-authored-by: Felix Guerin <[email protected]> * Fix typo Co-authored-by: Felix Guerin <[email protected]> --------- Co-authored-by: Felix Guerin <[email protected]>
- Loading branch information
Showing
10 changed files
with
120 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@288-toolkit/url': minor | ||
--- | ||
|
||
Refactor the code around parsed and entry |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Decodes the pathname by splitting it into parts, decoding each part, and joining them with slashes. | ||
* @param pathname - The pathname to decode. | ||
* @returns The decoded pathname. | ||
*/ | ||
export const decodePath = (pathname: string) => { | ||
return pathname.split('/').map(decodeURIComponent).join('/'); | ||
}; |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export * from './createEntryUrlBuilder.js'; | ||
export * from './decodePath.js'; | ||
export * from './isExternalUrl.js'; | ||
export * from './validateSameOrigin.js'; | ||
export * from './normalizePath.js'; | ||
export * from './parsedUrl.js'; | ||
export * from './urlCanParse.js'; | ||
export * from './validateSameOrigin.js'; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Returns the URL string without the protocol, composed of the hostname, pathname, search, and hash. | ||
* It starts with a double slash. | ||
* @param url - The URL to convert. | ||
*/ | ||
export const protocolLessUrl = (url: URL) => { | ||
const { hostname, pathname, hash, search } = url; | ||
return `//${hostname}${pathname}${search}${hash}`; | ||
}; | ||
|
||
/** | ||
* Returns the URL string without the scheme, composed of the pathname, search, and hash. | ||
* It starts with a single slash. | ||
* @param url - The URL to convert. | ||
*/ | ||
export const schemeLessUrl = (url: URL) => { | ||
const { pathname, hash, search } = url; | ||
return `${pathname}${search}${hash}`; | ||
}; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { normalize } from '@288-toolkit/strings'; | ||
|
||
/** | ||
* Normalizes the pathname by decoding it, normalizing each part, and joining them with slashes. | ||
* @see {@link @288-toolkit/strings#normalize} | ||
* @param pathname - The pathname to normalize. | ||
* @returns The normalized pathname. | ||
*/ | ||
export const normalizePath = (pathname: string) => { | ||
return pathname | ||
.split('/') | ||
.map((part) => normalize(decodeURIComponent(part))) | ||
.join('/'); | ||
}; |
This file contains 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 characters
This file contains 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 characters