@simongrasinovski/str-utils
Version:
A lightweight utility library for effortless string manipulation. Simplify common tasks like case validation, conversion and formatting with easy-to-use functions that enhance your JavaScript applications
24 lines (22 loc) • 634 B
JavaScript
;
var _require = require('./utils'),
ensureString = _require.ensureString;
var _require2 = require('./constants'),
VOWELS_REGEX = _require2.VOWELS_REGEX;
/**
* Counts the number of vowels in a string.
*
* @function
* @param {string} input - The string to analyze.
* @returns {number} Count of vowels.
*
* @throws {TypeError} Throws an error if the input is not a string.
*
* @example
* const result = countVowels('hello world');
* console.log(result); // 3
*/
module.exports = ensureString(function (input) {
var vowels = input.match(VOWELS_REGEX);
return vowels ? vowels.length : 0;
});