is-whitespace-character
Version:
Check if a character is a whitespace character
15 lines (14 loc) • 407 B
JavaScript
/**
* Check if the given character code, or the character code at the first
* character, is a whitespace character.
*
* @param {string|number} character
* @returns {boolean} Whether `character` is a whitespace character
*/
export function isWhitespaceCharacter(character) {
return /\s/.test(
typeof character === 'number'
? String.fromCharCode(character)
: character.charAt(0)
)
}