mentions-hashtags
v1.0.2
Published
A tiny utility package to extract social media mentions (@user) and hashtags (#tag) with multilingual normalization support.
Maintainers
Readme
📦 mentions-hashtags
A tiny, zero-dependency utility to extract social media-style mentions (@username) and hashtags (#topic) from any text. Includes multilingual Unicode normalization and optional deduplication.
✨ Features
- ✅ Extract
@mentionsand#hashtagsfrom text - 🌍 Unicode normalization (e.g., accented characters)
- 🔁 Configurable deduplication with
uniqueflag - ⚡️ Lightweight, blazing fast, zero dependencies
- 🎯 Ideal for Instagram, YouTube, TikTok, and Twitter/X content: fashion, beauty, luxury, and sports
📥 Installation
npm install mentions-hashtags🚀 Quick Example
const { parseMentionsAndHashtags } = require('mentions-hashtags');
const input = "Huge thanks to @Gucci and @vogueparis for the stunning event! #FashionWeek #LuxuryStyle #VogueMoment";
const result = parseMentionsAndHashtags(input, {
mentions: true,
hashtags: true,
unique: true
});
console.log(result);
/*
{
mentions: ['@gucci', '@vogueparis'],
hashtags: ['#fashionweek', '#luxurystyle', '#voguemoment']
}
*/🔍 API Reference
parseMentionsAndHashtags(description, options)
| Param | Type | Default | Description |
|------------------|-----------|---------|--------------------------------|
| description | string | — | The input string to parse |
| options.mentions | boolean | true | Whether to extract @mentions |
| options.hashtags | boolean | true | Whether to extract #hashtags |
| options.unique | boolean | true | Whether to deduplicate results |
Returns:
{
mentions: string[] | null,
hashtags: string[] | null
}parseMentions(description, { unique })
parseMentions("@Dior @dior @FentyBeauty");
// → ['@dior', '@fentybeauty']parseHashtags(description, { unique })
parseHashtags("#Skincare #BeautyTips #beautytips");
// → ['#skincare', '#beautytips']convertStyledToNormal(description)
convertStyledToNormal("Crème de la crème by @Chanel #BeautéLuxe");
// → "Creme de la creme by @Chanel #BeauteLuxe"📱 Real-World Social Media Examples
✅ Instagram Fashion Post
const input = "Styled by @balenciaga and shot by @highfashionlens 📸 #RunwayReady #ParisFashion #BalenciagaVibes";
parseMentionsAndHashtags(input);
/*
mentions: ['@balenciaga', '@highfashionlens']
hashtags: ['#runwayready', '#parisfashion', '#balenciagavibes']
*/✅ YouTube Beauty Review
const input = "Loving the new @FentyBeauty gloss 💄✨ #MakeupReview #BeautyCommunity";
parseMentionsAndHashtags(input);
/*
mentions: ['@fentybeauty']
hashtags: ['#makeupreview', '#beautycommunity']
*/✅ TikTok Football Highlight
const input = "⚽ What a goal by @Cristiano! #UCLFinal #FootballLegend #GOAT";
parseMentionsAndHashtags(input);
/*
mentions: ['@cristiano']
hashtags: ['#uclfinal', '#footballlegend', '#goat']
*/🧪 Running Tests
npm install
npm test📄 License
MIT License © [rocketnozzle.io]
