npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

word-link

v1.0.1

Published

Allows you to convert specific words into links.

Downloads

18

Readme

Word Link

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);

| | Argument | Type | Default | Details | |---|-------------------|--------------|----------------------------------------|------------------------------------------------------------------------------| | 1 | text | String | | Text in which you want to replace the word to word-links. | | 2 | word | String | | A String or RegExp that is to be replaced by word-link. | | 3 | url | String | | A URL to be used to generate a word-link. | | 4 | opts | Dictionary | | (optional) Additional seetings. | | | opts.debug | Boolean | false | (optional) Enable debugging mode. Shows a console.log with replaced words. | | | opts.excludedTags | Array | ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'] | (optional) List of HTML tags to be ignored during replacement. | | | opts.attributes | Object | {} | (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

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