index.js 503 B

1234567891011121314151617
  1. /**
  2. * Check if the given character code, or the character code at the first
  3. * character, is hexadecimal.
  4. *
  5. * @param {string|number} character
  6. * @returns {boolean} Whether `character` is hexadecimal
  7. */
  8. export function isHexadecimal(character) {
  9. const code =
  10. typeof character === 'string' ? character.charCodeAt(0) : character
  11. return (
  12. (code >= 97 /* a */ && code <= 102) /* z */ ||
  13. (code >= 65 /* A */ && code <= 70) /* Z */ ||
  14. (code >= 48 /* A */ && code <= 57) /* Z */
  15. )
  16. }