Last active
November 16, 2023 10:31
-
-
Save kvnxiao/bf4ae8cc6838509b101663895a195bae to your computer and use it in GitHub Desktop.
Generate KeyboardEvent.code values from MDN Table
This file contains hidden or 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
// Generates string union type values from Keyboard event code values taken from the MDN table located at: | |
// https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values#code_values_on_windows | |
const table = document.querySelector("table.standard-table"); | |
const firefox = table.querySelectorAll("tbody > tr > td:nth-child(2) > code:first-child"); | |
const ignoreList = ["\"\"", "\"Unidentified\""]; | |
const codes = [...new Set([...firefox].map((node) => node.innerText))].filter(s => !ignoreList.includes(s)); | |
console.log("export type KeyCode =", codes.join("\n | ")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment