npm.io
0.0.1 • Published 9 years ago

mention-parser

Licence
MIT
Version
0.0.1
Deps
0
Vulns
0
Weekly
0

mention-parser Build Status

Parse and replace mentions from string

Install

$ yarn add mention-parser

Usage

const mentionParser = require('mention-parser')

const str = 'hey @bukinoshita and @here, check this #channel!'

mentionParser(str).get()
// => ['@bukinoshita', '@here']

mentionParser(str, { prefix: '#' }).get()
// => ['#channel']

mentionParser(str).replace(mention => `<a href="/channel">${mention}</a>`)
// => 'hey <a href="/bukinoshita">@bukinoshita</a> and <a href="/here">@here</a>, check this #channel!'

API

mentionParser(input, [options])
input

Type: string
Required

string to be parsed

options

Type: object

prefix

Type: string
Default: @
Options: @ or #

methods
.get()

Returns an array with mentions

.replace(fn)
fn

Type: function

License

MIT Bu Kinoshita

Keywords