UNPKG

@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) 670 B
"use strict"; var _require = require('./utils'), ensureString = _require.ensureString; var _require2 = require('./constants'), CONSONANTS_REGEX = _require2.CONSONANTS_REGEX; /** * Counts the number of consonants in a string. * * @function * @param {string} input - The string to analyze. * @returns {number} Count of consonants. * * @throws {TypeError} Throws an error if the input is not a string. * * @example * const result = countConsonants('hello world'); * console.log(result); // 7 */ module.exports = ensureString(function (input) { var consonants = input.match(CONSONANTS_REGEX); return consonants ? consonants.length : 0; });