mention-parser

0.0.1 • Public • Published

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

Package Sidebar

Install

npm i mention-parser

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • bukinoshita