Skip to content

Commit

Permalink
feat: isEmptyURL and isNonEmptyURL utils
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 22, 2021
1 parent 0168c21 commit 3c1c6d8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function cleanDoubleSlashes (input: string = ''): string {
}

export function withBase (input: string, base: string) {
if (!base || base === '/') {
if (isEmptyURL(base)) {
return input
}
const _base = withoutTrailingSlash(base)
Expand All @@ -47,7 +47,7 @@ export function withBase (input: string, base: string) {
}

export function withoutBase (input: string, base: string) {
if (!base || base === '/') {
if (isEmptyURL(base)) {
return input
}
const _base = withoutTrailingSlash(base)
Expand All @@ -68,6 +68,14 @@ export function getQuery (input: string): QueryObject {
return parseQuery(parseURL(input).search)
}

export function isEmptyURL (url: string) {
return !url || url === '/'
}

export function isNonEmptyURL (url: string) {
return url && url !== '/'
}

export function joinURL (base: string, ...input: string[]): string {
let url = base || ''

Expand Down

0 comments on commit 3c1c6d8

Please sign in to comment.