@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
17 lines (16 loc) • 643 B
TypeScript
/**
* Counts the number of words in the given text that match a specified pattern.
*
* @param text - The input text to search within.
* @param pattern - The pattern to match words against (RegExp or string).
* @returns The number of words that match the given pattern.
*
* @example
* // Using a regular expression to count words starting with "a"
* countWordsMatching("apple banana apricot avocado", /^a/); // 3
*
* @example
* // Using a string to count exact matches
* countWordsMatching("apple banana apple apricot", "apple"); // 2
*/
export default function countWordsMatching(text: string, pattern: RegExp | string): number;