Coder Social home page Coder Social logo

jlsuarezs / anchorme.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexcorvi/anchorme.js

0.0 2.0 0.0 169 KB

Javascript function to convert URLs in text to clickable HTML anchor links

Home Page: http://alexcorvi.github.io/anchorme.js/

License: MIT License

JavaScript 87.17% HTML 12.83%

anchorme.js's Introduction

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 key Default value Description
attributes false An object of attributes to be added to each anchor tag
html true If you're expecting HTML input, this will make sure that your HTML won't break
ips true Detect IPs
urls true Detect URLs
email true Detect Emails
truncate 0 Truncate 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("[email protected]"); // 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

anchorme.js's People

Contributors

alexcorvi avatar ali-saleem avatar azagniotov avatar chrisoelmueller avatar davidschlachter avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.