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
50 changed files
with
1,241 additions
and
1,172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,51 @@ | ||
export const addLeadingSlash = (path) => | ||
path.charAt(0) === '/' ? path : '/' + path | ||
export const addLeadingSlash = path => | ||
path.charAt(0) === "/" ? path : "/" + path | ||
|
||
export const stripLeadingSlash = (path) => | ||
path.charAt(0) === '/' ? path.substr(1) : path | ||
export const stripLeadingSlash = path => | ||
path.charAt(0) === "/" ? path.substr(1) : path | ||
|
||
export const hasBasename = (path, prefix) => | ||
path.toLowerCase().lastIndexOf(prefix.toLowerCase(), 0) === 0 && "/?#".indexOf(path.charAt(prefix.length)) !== -1 | ||
|
||
export const stripBasename = (path, prefix) => | ||
hasBasename(path, prefix) ? path.substr(prefix.length) : path | ||
|
||
export const stripTrailingSlash = (path) => | ||
path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path | ||
export const stripTrailingSlash = path => | ||
path.charAt(path.length - 1) === "/" ? path.slice(0, -1) : path | ||
|
||
export const parsePath = (path) => { | ||
let pathname = path || '/' | ||
let search = '' | ||
let hash = '' | ||
export const parsePath = path => { | ||
let pathname = path || "/" | ||
let search = "" | ||
let hash = "" | ||
|
||
const hashIndex = pathname.indexOf('#') | ||
const hashIndex = pathname.indexOf("#") | ||
if (hashIndex !== -1) { | ||
hash = pathname.substr(hashIndex) | ||
pathname = pathname.substr(0, hashIndex) | ||
} | ||
|
||
const searchIndex = pathname.indexOf('?') | ||
const searchIndex = pathname.indexOf("?") | ||
if (searchIndex !== -1) { | ||
search = pathname.substr(searchIndex) | ||
pathname = pathname.substr(0, searchIndex) | ||
} | ||
|
||
return { | ||
pathname, | ||
search: search === '?' ? '' : search, | ||
hash: hash === '#' ? '' : hash | ||
search: search === "?" ? "" : search, | ||
hash: hash === "#" ? "" : hash | ||
} | ||
} | ||
|
||
export const createPath = (location) => { | ||
export const createPath = location => { | ||
const { pathname, search, hash } = location | ||
|
||
let path = pathname || '/' | ||
let path = pathname || "/" | ||
|
||
if (search && search !== '?') | ||
path += (search.charAt(0) === '?' ? search : `?${search}`) | ||
|
||
if (hash && hash !== '#') | ||
path += (hash.charAt(0) === '#' ? hash : `#${hash}`) | ||
if (search && search !== "?") | ||
path += search.charAt(0) === "?" ? search : `?${search}` | ||
|
||
if (hash && hash !== "#") path += hash.charAt(0) === "#" ? hash : `#${hash}` | ||
|
||
return path | ||
} |
Oops, something went wrong.