@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.
20 lines • 694 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = extractMentions;
/**
* 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"]
*/
function extractMentions(str) {
const mentionRegex = /@\w+/g;
const matches = str.match(mentionRegex);
return matches ? matches : [];
}
//# sourceMappingURL=extractMentions.js.map