Skip to content

Commit

Permalink
lint-fix and types
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 9, 2022
1 parent bf7a7d8 commit 8bee034
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/next/shared/lib/router/utils/prepare-destination.ts
Expand Up @@ -49,16 +49,17 @@ export function matchHas(
if (!hasItem.value && value) {
params[getSafeParamName(key!)] = value
return true
} else if (typeof(value) !== 'undefined') {
} else if (typeof value !== 'undefined') {
const matcher = new RegExp(`^${hasItem.value}$`)
// a value of false is equivalent to ''
// e.g. /path?q - q is false and should be matched as ''
const match = (v) => String(v || '').match(matcher)
const match = (v?: string) => String(v || '').match(matcher)

let matches: ReturnType<typeof match> = null

let matches
if (Array.isArray(value)) {
// any match in an array means we have it
value.some((v) => matches = match(v))
value.some((v) => (matches = match(v)))
} else {
matches = match(value)
}
Expand All @@ -67,7 +68,7 @@ export function matchHas(
if (Array.isArray(matches)) {
if (matches.groups) {
Object.keys(matches.groups).forEach((groupKey) => {
params[groupKey] = matches.groups![groupKey]
params[groupKey] = matches?.groups![groupKey]
})
} else if (hasItem.type === 'host' && matches[0]) {
params.host = matches[0]
Expand Down

0 comments on commit 8bee034

Please sign in to comment.