From 89aa85364f8cb1aadea261ce85dbb62e491f85a6 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 8 Nov 2020 22:51:56 -0800 Subject: [PATCH] Small change to more idiomatic typescript (#31) --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6059af7..1e23430 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,10 +61,10 @@ export default ({ const errors = []; if (typeof value === 'string') { - const lowercaseCount = (value.match(/[a-z]/g) || []).length; - const upperCaseCount = (value.match(/[A-Z]/g) || []).length; - const numericCount = (value.match(/[0-9]/g) || []).length; - const symbolCount = (value.match(/[^a-zA-Z0-9]/g) || []).length; + const lowercaseCount = value.match(/[a-z]/g)?.length ?? 0; + const upperCaseCount = value.match(/[A-Z]/g)?.length ?? 0; + const numericCount = value.match(/[0-9]/g)?.length ?? 0; + const symbolCount = value.match(/[^a-zA-Z0-9]/g)?.length ?? 0; const meetsMin = min && value.length >= min; const meetsMax = max && value.length <= max;