🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

parse-mentions

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-mentions

Parse and optionally replace @ mentions from a string of text.

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
55
3.77%
Maintainers
1
Weekly downloads
 
Created
Source

parse-mentions NPM version NPM downloads Build Status

Parse and optionally replace @ mentions from a string of text.

Install

Install with npm:

$ npm install --save parse-mentions

Usage

var parse = require('parse-mentions');

API

parse

Parse a string to retrieve or replace @ mention strings.

Params

  • str {String}: Input string to parse looking for @ mentions.
  • options {Object}: Optional options object to control the output of the @ mentions
  • options.stringify {Boolean}: Should the @ mentions be stringified in the output array. When false an object with additional information about the mention is returned. Defaults to true.
  • fn {Function}: Optional replace function. When passed in, the @ mentions are replaced in the string instead of returned as an array. The new string is returned.
  • returns {String|Array}: Array of mentions when a replace function is not passed in.

Example

// get an array of @ mention strings
var mentions = parse('- @doowb\n- @jonschlinkert');
console.log(mentions);
//=> ['doowb', 'jonschlinkert']

// replace @ mention strings with a url
var str = parse('- @doowb\n- @jonschlinkert', function(name) {
return `[@${name}](https://github.com/${name})`;
});
console.log(str);
//=> - [@doowb](https://github.com/doowb)
//=> - [@jonschlinkert](https://github.com/jonschlinkert)

// get an array of @ mention objects
var mentions = parse('- @doowb\n- @jonschlinkert', {stringify: false});
console.log(mentions);
//=> [
//=>   {name: 'doowb', mention: '@doowb', index: 2},
//=>   {name: 'jonschlinkert', mention: '@jonschlinkert', index: 11}
//=> ]

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for avice on opening issues, pull requests, and coding standards.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Brian Woodward

License

Copyright © 2016, Brian Woodward. Released under the MIT license.

This file was generated by verb-generate-readme, v0.1.30, on September 24, 2016.

Keywords

@-mention

FAQs

Package last updated on 24 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts