Socket
Socket
Sign inDemoInstall

anchorify

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

anchorify

Convert urls to anchor tags inside a string


Version published
Weekly downloads
977
increased by11.78%
Maintainers
1
Install size
1.41 MB
Created
Weekly downloads
 

Changelog

Source

1.0.2 (2017-06-06)

Bug Fixes

  • skip existing anchor tags in multiple lines (c4673bf)

<a name="1.0.1"></a>

Readme

Source

Anchorify

Convert all links inside a string to HTML anchor tags. It supports.

Travis

  1. URLs with(out) protocol.
  2. Detect email vs plain URLs.
  3. Adds rel="noreferrer noopener" as a security measure.
  4. Normalizes urls without procotol or www.
  5. Recognize existing anchor tags.

Installation

The code is hand-written in ES5 and is supposed to work with all major browsers. It makes use of var over let or const and for over forEach.

But you will need a commonjs module loader to make use of it.

npm i --save anchorify

Usage

const anchorify = require('anchorify')

assert.equal(
  anchorify('Visit google.com'),
  'Visit <a href="http://google.com"> google.com </a>'
)

// Set custom target
assert.equal(
  anchorify('Visit google.com', { target: '_blank' }),
  'Visit <a href="http://google.com" target="_blank" ref="noreferrer noopener"> google.com </a>'
)

// Do not touch existing anchor tags
assert.equal(
  anchorify('Visit <a href="http://google.com"> google.com </a>', { target: '_blank' }),
  'Visit <a href="http://google.com"> google.com </a>'
)

// Detect email
assert.equal(
  anchorify('You can reach me at foo@bar.com'),
  'You can reach me at <a href="mailto:foo@bar.com"> foo@bar.com </a>'
)

// Let browser decide the protocol
assert.equal(
  anchorify('Open //google.com'),
  'Open <a href="//google.com"> google.com </a>'
)

Keywords

FAQs

Last updated on 06 Jun 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc