Skip to content

Instantly share code, notes, and snippets.

@jrrio
Last active April 5, 2019 21:16
Show Gist options
  • Save jrrio/45414de05bd205bb09d9635be07eeec3 to your computer and use it in GitHub Desktop.
Save jrrio/45414de05bd205bb09d9635be07eeec3 to your computer and use it in GitHub Desktop.
JavaScript Utilility functions
// 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