Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anchorme

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anchorme

A library to convert URLs to a clickable HTML anchor elements

  • 0.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
73K
increased by4.15%
Maintainers
1
Weekly downloads
 
Created
Source

Anchorme.js

A library to convert URLs to a click-able HTML anchor elements

Features

  • Highly sensitive.
  • produces the least possible false positives if any.
  • Skips HTML, so it doesn't break your HTML if it had a URL as an attribute for an element.
  • Links with or without protocols.
  • Preserve upper and lower case, although when detecting, it's basically case insensitive.
  • Checks against full IANA list of TLDs.
  • Works with IPs, FTPs, Emails and files.
  • Also works when ports are defined.
  • Small in size.
  • No RegExp involved, very readable and maintainable.
  • Supports setting custom attributes with any values.
  • Supports checking IPs only, Emails only, or URLs only.
  • Helper methods can be used for other purposes.

Getting Started

Download

File

Download the library from dist folder (either anchorme.js or anchorme.min.js).

NPM

Install via NPM: npm install anchorme

Usage


var anchorme = require("anchorme"); // if installed via NPM

var someText = "this is a text with a link www.github.com ..";
var result = anchorme(someText);

// You can also pass few options

anchorme(someText,{
  attribute:{
    "target":"_blank"
  }
})

Available options
Option keyDefault valueDescription
attributesfalseAn object of attributes to be added to each anchor tag
htmltrueIf you're expecting HTML input, this will make sure that your HTML won't break
ipstrueDetect IPs
urlstrueDetect URLs
emailtrueDetect Emails
truncate0Truncate long links
defaultProtocol"http://"Default protocol to be added when no protocol has been defined in the input

Validation

it can also be used for validation:

anchorme.validate.ip("1.1.1.1:3000/something"); // returns true
anchorme.validate.email("alex@array.com"); // return true
anchorme.validate.url("google.co.uk"); // returns true

Demo

To test how this library would work for you, head over to here to test it.


License: The MIT License (MIT) - Copyright (c) 2016 Alex Corvi

Keywords

FAQs

Package last updated on 18 Nov 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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc