You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
725 B

/**
* @author Titus Wormer
* @copyright 2016 Titus Wormer
* @license MIT
* @module is-whitespace-character
* @fileoverview Check if a character is a whitespace character.
*/
'use strict';
/* eslint-env commonjs */
/* Expose. */
module.exports = whitespace;
/* Methods. */
var fromCode = String.fromCharCode;
/* Constants. */
var re = /\s/;
/**
* Check whether the given character code, or the character
* code at the first character, is a whitespace character.
*
* @param {string|number} character
* @return {boolean} - Whether `character` is a whitespaces character.
*/
function whitespace(character) {
return re.test(
typeof character === 'number' ? fromCode(character) : character.charAt(0)
);
}