isOnlyWhitespace.js 428 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const isWhitespace = require('./isWhitespace');
  3. /**
  4. * Returns a Boolean indicating whether the the input string is only whitespace.
  5. *
  6. * @param {string} input
  7. * @returns {boolean}
  8. */
  9. module.exports = function (input) {
  10. let isOnlyWhitespace = true;
  11. for (let i = 0, l = input.length; i < l; i++) {
  12. if (!isWhitespace(input[i])) {
  13. isOnlyWhitespace = false;
  14. break;
  15. }
  16. }
  17. return isOnlyWhitespace;
  18. };