Last active
August 5, 2021 03:55
-
-
Save lbragile/3176be88d6c374e4b69ab86659c03e7c to your computer and use it in GitHub Desktop.
A complete HEX string type using Template Literal Types
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
// https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html | |
type THexBase = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; | |
type THexLower = "a" | "b" | "c" | "d" | "e" | "f"; | |
type THexUpper = "A" | "B" | "C" | "D" | "E" | "F"; | |
/** | |
* Includes 1 & 2 character hex strings. | |
* | |
* @example "0", "00", ..., "f", "ff", ..., "F", "FF" | |
*/ | |
type THexStr = | |
| `${THexBase}${THexBase}` | |
| `${THexBase}${THexLower}` | |
| `${THexLower}${THexBase}` | |
| `${THexBase}${THexUpper}` | |
| `${THexUpper}${THexBase}` | |
| `${THexLower}${THexLower}` | |
| `${THexLower}${THexUpper}` | |
| `${THexUpper}${THexLower}` | |
| `${THexUpper}${THexUpper}` | |
| THexBase | |
| THexLower | |
| THexUpper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment