From 23433c32d4c7a79620c2486b55c46cab79f47a69 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sun, 12 Mar 2023 11:13:33 +0800 Subject: [PATCH] Remove uncovered lines Only keep lines that are testable. --- src/index.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 400544b..21be54a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -526,6 +526,11 @@ const INPUT_TYPE_EMAIL = 'email' as const; */ const INPUT_TYPE_TEL = 'tel' as const; +/** + * Value of the `type` attribute for `` elements considered as URL fields. + */ +const INPUT_TYPE_URL = 'url' as const; + /** * Value of the `type` attribute for `` elements considered as password fields. */ @@ -567,6 +572,7 @@ const getInputFieldValue = ( case INPUT_TYPE_TEXT: case INPUT_TYPE_EMAIL: case INPUT_TYPE_TEL: + case INPUT_TYPE_URL: case INPUT_TYPE_PASSWORD: case INPUT_TYPE_HIDDEN: case INPUT_TYPE_COLOR: @@ -624,6 +630,7 @@ const setInputFieldValue = ( case INPUT_TYPE_TEXT: case INPUT_TYPE_EMAIL: case INPUT_TYPE_TEL: + case INPUT_TYPE_URL: case INPUT_TYPE_PASSWORD: case INPUT_TYPE_HIDDEN: case INPUT_TYPE_COLOR: @@ -718,17 +725,12 @@ const ATTRIBUTE_DISABLED = 'disabled' as const; * @returns Value determining if the element is a named and enabled form field. */ export const isNamedEnabledFormFieldElement = (el: HTMLElement) => { - if (!(ATTRIBUTE_NAME in el)) { - return false; - } - if (typeof el[ATTRIBUTE_NAME] !== 'string') { - return false; - } - const namedEl = el as unknown as HTMLElementWithName; + const namedEl = el as unknown as Record; return ( - el[ATTRIBUTE_NAME].length > 0 + typeof namedEl[ATTRIBUTE_NAME] === 'string' + && namedEl[ATTRIBUTE_NAME].length > 0 && !(ATTRIBUTE_DISABLED in namedEl && Boolean(namedEl[ATTRIBUTE_DISABLED])) - && isFormFieldElement(namedEl) + && isFormFieldElement(namedEl as unknown as HTMLElement) ); };