From 90a68ce214ce351880882c1d64d7eade8eff3899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Thu, 3 Feb 2022 12:53:47 +0100 Subject: [PATCH 1/2] refactor: Leverage early return --- src/matches.ts | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/matches.ts b/src/matches.ts index b649cb69..f7a3ff3b 100644 --- a/src/matches.ts +++ b/src/matches.ts @@ -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}) + 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} From 02ac9668a515568e607c796923b7e85818f85d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Thu, 3 Feb 2022 12:59:09 +0100 Subject: [PATCH 2/2] fix whitespaces --- src/matches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matches.ts b/src/matches.ts index f7a3ff3b..31670d1d 100644 --- a/src/matches.ts +++ b/src/matches.ts @@ -93,7 +93,7 @@ function makeNormalizer({ }: NormalizerOptions) { if (!normalizer) { // No custom normalizer specified. Just use default. - return getDefaultNormalizer({trim, collapseWhitespace}) + return getDefaultNormalizer({trim, collapseWhitespace}) } if (