UNPKG

@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 597 B
/** * Extracts all mentions from a given string. * * @param str - The input string to extract mentions from. * @returns An array of mentions found in the string. * * @example * extractMentions("Hello @user1 and @user2!"); // Output: ["@user1", "@user2"] * extractMentions("No mentions here!"); // Output: [] * extractMentions("@admin please check this."); // Output: ["@admin"] */ export default function extractMentions(str) { const mentionRegex = /@\w+/g; const matches = str.match(mentionRegex); return matches ? matches : []; } //# sourceMappingURL=extractMentions.js.map