Skip to content

refactor: Leverage early return #1102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions src/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,24 @@ function makeNormalizer({
collapseWhitespace,
normalizer,
}: NormalizerOptions) {
if (normalizer) {
// User has specified a custom normalizer
if (
typeof trim !== 'undefined' ||
typeof collapseWhitespace !== 'undefined'
) {
// They've also specified a value for trim or collapseWhitespace
throw new Error(
'trim and collapseWhitespace are not supported with a normalizer. ' +
'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' +
'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer',
)
}

return normalizer
} else {
if (!normalizer) {
// No custom normalizer specified. Just use default.
return getDefaultNormalizer({trim, collapseWhitespace})
}

if (
typeof trim !== 'undefined' ||
typeof collapseWhitespace !== 'undefined'
) {
// They've also specified a value for trim or collapseWhitespace
throw new Error(
'trim and collapseWhitespace are not supported with a normalizer. ' +
'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' +
'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer',
)
}

return normalizer
}

export {fuzzyMatches, matches, getDefaultNormalizer, makeNormalizer}