-
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.
- Loading branch information
Showing
13 changed files
with
83 additions
and
92 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
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 was deleted.
Oops, something went wrong.
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,46 @@ | ||
export function cacheable(func) { | ||
const cache = {}; | ||
return function (arg) { | ||
if (!(arg in cache)) | ||
cache[arg] = func(arg); | ||
return cache[arg]; | ||
}; | ||
} | ||
|
||
const join = (...paths) => { | ||
let fullPath = paths | ||
.filter(Boolean) | ||
.filter(path => '/' !== path) | ||
.map(addHeadRemoveTail) | ||
.join(''); | ||
|
||
const last = paths[paths.length - 1]; | ||
if (last && last.endsWith('/')) | ||
fullPath += '/'; | ||
|
||
return fullPath || '/'; | ||
}; | ||
|
||
const addHeadRemoveTail = path => path | ||
.replace(/\/+$/, '') | ||
.replace(/^(?=[^/])/, '/'); | ||
|
||
const separate = origin => { | ||
let pathname; | ||
let search; | ||
const index = origin.indexOf('?'); | ||
if (index === -1) { | ||
pathname = origin; | ||
search = ''; | ||
} else { | ||
pathname = origin.slice(0, index); | ||
search = origin.slice(index); | ||
} | ||
return { pathname, search }; | ||
}; | ||
|
||
export { | ||
join, | ||
addHeadRemoveTail, | ||
separate, | ||
}; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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