@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.
30 lines • 1.12 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
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