Last active
April 5, 2019 21:16
-
-
Save jrrio/45414de05bd205bb09d9635be07eeec3 to your computer and use it in GitHub Desktop.
JavaScript Utilility functions
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
// Test for numeric value. | |
function isNumeric(n) { | |
return !isNaN(parseFloat(n)) && isFinite(n); | |
} | |
/** | |
* @param {Event} e | |
* @see <https://www.w3.org/TR/uievents/#interface-keyboardevent> | |
* All browsers (IE11, Chrome, FF, etc.) support event.key. | |
* event.keyCode, charCode and event.which are deprecated. | |
*/ | |
function isModifierKey(e) { | |
let key = e.key; // key value of the key pressed. | |
return (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || | |
key == "Backspace" || key == "Tab" || | |
key == "Delete" || key == "Enter"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment