New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

word-link

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

word-link

Allows you to convert specific words into links.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Allows you to convert specific words into links. Inspired by Drupal module word_link.

This can be useful for crossposting your site's pages, or for the contextual advertising of your partners (SEO).

Installation

  • Latest release
  • Bower: bower install word-link
  • NPM: npm install word-link

Usage

WordLink.apply(text, word|regexp, url, opts);

ArgumentTypeDefaultDetails
1textStringText in which you want to replace the word to word-links.
2wordStringA String or RegExp that is to be replaced by word-link.
3urlStringA URL to be used to generate a word-link.
4optsDictionary(optional) Additional seetings.
opts.debugBooleanfalse(optional) Enable debugging mode. Shows a console.log with replaced words.
opts.excludedTagsArray['H1', 'H2', 'H3', 'H4', 'H5', 'H6'](optional) List of HTML tags to be ignored during replacement.
opts.attributesObject{}(optional) Additional attributes for a link.

Returns

Type: String

Text with replaced word-links.

Examples

var WordLink = require('word-link');
var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

Replace words with a link:

WordLink.apply(text, 'ipsum', 'http://example.com');
// "Lorem <a href="http://example.com">ipsum</a> dolor sit amet, consectetur adipiscing elit."

Find words with regex and replace them with a link:

WordLink.apply(text, '(ipsum|elit)', 'http://example.com');
// "Lorem <a href="http://example.com">ipsum</a> dolor sit amet, consectetur adipiscing <a href="http://example.com">elit</a>."

Word Link understands html. It will ignore existed links and tag attributes:

var html = '<p>Lorem <a href="http://ipsum.com" class="ipsum">ipsum</a> dolor sit amet, consectetur adipiscing elit.</p>';

WordLink.apply(html, 'ipsum', 'http://example.com');
// "<p>Lorem <a href="http://ipsum.com" class="ipsum">ipsum</a> dolor sit amet, consectetur adipiscing elit.</p>"

TODOs

  • A setting for tags to be ignored.
  • Additional attributes for a link.
  • Add tests.
  • Nodejs version.

Keywords

word

FAQs

Package last updated on 29 Aug 2018

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