generated from finsweet/developer-starter
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created new typeguards/instances utils
- Loading branch information
1 parent
0024923
commit a57b300
Showing
8 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@finsweet/ts-utils': minor | ||
--- | ||
|
||
Created new typeguards/instances utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const isNode = (target: unknown): target is Node => target instanceof Node; | ||
|
||
export const isElement = (target: unknown): target is Element => target instanceof Element; | ||
|
||
export const isHTMLElement = (target: unknown): target is HTMLElement => target instanceof HTMLElement; | ||
|
||
export const isHTMLInputElement = (target: unknown): target is HTMLInputElement => target instanceof HTMLInputElement; | ||
|
||
export const isHTMLSelectElement = (target: unknown): target is HTMLSelectElement => | ||
target instanceof HTMLSelectElement; | ||
|
||
export const isHTMLTextAreaElement = (target: unknown): target is HTMLTextAreaElement => | ||
target instanceof HTMLTextAreaElement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import type { FormField } from '../types/FormField'; | ||
import { isHTMLInputElement, isHTMLSelectElement, isHTMLTextAreaElement } from './instances'; | ||
|
||
/** | ||
* Checks if an element is a form field element | ||
* @param element | ||
*/ | ||
// prettier-ignore | ||
export const isFormField = (element: Element | EventTarget | null): element is FormField => element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement; | ||
export const isFormField = (element: Element | EventTarget | null): element is FormField => isHTMLInputElement(element) || isHTMLSelectElement(element) || isHTMLTextAreaElement(element); |