{"id":10526,"library":"autolinker","title":"Autolinker.js","description":"Autolinker.js is a robust JavaScript utility designed to automatically detect and convert various patterns like URLs, email addresses, phone numbers, and social media mentions/hashtags (Twitter, Instagram, YouTube, TikTok, Facebook, Soundcloud) within plain text or HTML into clickable hyperlinks. The current stable version is `v4.1.5`. The library maintains an active release cadence, frequently publishing minor and patch updates, often focusing on performance enhancements and bug fixes. A key differentiator is its rewritten URL parser in `v4.0.0`, which utilizes a finite state machine for `O(n)` linear time performance, significantly improving speed and preventing 'catastrophic backtracking' issues common with regular expression-based parsers. Unlike many alternatives, Autolinker.js is meticulously designed to correctly handle HTML input, avoiding the creation of nested anchor tags or inadvertently modifying existing `href` attributes, making it particularly suitable for processing rich text content where correctness and performance are critical.","status":"active","version":"4.1.5","language":"javascript","source_language":"en","source_url":"git://github.com/gregjacobs/Autolinker.js","tags":["javascript","auto","link","autolink","url","urls","anchor","typescript"],"install":[{"cmd":"npm install autolinker","lang":"bash","label":"npm"},{"cmd":"yarn add autolinker","lang":"bash","label":"yarn"},{"cmd":"pnpm add autolinker","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary `Autolinker` class is exported as a default export since v2. Using named import is incorrect.","wrong":"import { Autolinker } from 'autolinker';","symbol":"Autolinker","correct":"import Autolinker from 'autolinker';"},{"note":"For CommonJS environments (Node.js), the package should be `require`d and typically aliased with a capital letter as it's a class.","wrong":"const autolinker = require('autolinker');","symbol":"Autolinker (CommonJS)","correct":"const Autolinker = require('autolinker');"},{"note":"The `Match` interface/type for TypeScript is available as a named export. Ensure you also import `Autolinker` as the default export if needed.","wrong":"import { Match } from 'autolinker';","symbol":"Match","correct":"import Autolinker, { Match } from 'autolinker';"}],"quickstart":{"code":"import Autolinker from 'autolinker';\n\nconst inputText: string = \"Check out my website at example.com, email me at test@example.org, or call me at +1 (123) 456-7890. Also, find me on Twitter @myhandle and hashtag #myproject.\";\n\nconst autolinker = new Autolinker({\n  urls: { scheme: true, www: true, ipV4Matches: true },\n  email: true,\n  phone: true,\n  mention: 'twitter',\n  hashtag: 'twitter',\n  newWindow: true,\n  stripPrefix: false,\n  // Custom replace function to add specific classes or attributes\n  replaceFn: (match) => {\n    const tag = match.buildTag();\n    if (match.getType() === 'url') {\n      tag.setAttr('class', 'my-url-link');\n    }\n    return tag;\n  }\n});\n\nconst linkedText: string = autolinker.link(inputText);\n\nconsole.log(linkedText);\n// Expected output: Check out my website at <a href=\"http://example.com\" class=\"my-url-link\" target=\"_blank\" rel=\"noopener noreferrer\">example.com</a>, email me at <a href=\"mailto:test@example.org\" target=\"_blank\" rel=\"noopener noreferrer\">test@example.org</a>, or call me at <a href=\"tel:+11234567890\" target=\"_blank\" rel=\"noopener noreferrer\">+1 (123) 456-7890</a>. Also, find me on Twitter <a href=\"https://twitter.com/myhandle\" target=\"_blank\" rel=\"noopener noreferrer\">@myhandle</a> and hashtag <a href=\"https://twitter.com/hashtag/myproject\" target=\"_blank\" rel=\"noopener noreferrer\">#myproject</a>.","lang":"typescript","description":"This quickstart demonstrates how to initialize Autolinker with various options and link a block of text, including a custom `replaceFn` to modify the generated anchor tags."},"warnings":[{"fix":"Review the official breaking changes documentation for v4.x.x, especially regarding URL parsing behavior and the `Match` object API. Adjust code that relied on custom regex or direct `Match.type` access.","message":"Autolinker v4.0.0 introduced significant breaking changes, primarily a complete rewrite of the URL parser from regular expressions to a finite state machine. This change, while greatly improving performance and preventing ReDoS attacks, removes the ability to override regular expressions in `Matcher` classes. The `urls.wwwMatches` config was also removed, and `Match.getType()` replaced `Match.type`.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Always pass raw or pre-processed text/HTML directly to `Autolinker.link()` and rely on its internal HTML parsing for correct behavior. Avoid manually replacing parts of the string that might contain valid HTML tags or already linked content.","message":"When migrating from older versions or other autolinking libraries, be aware that Autolinker.js explicitly handles HTML input to prevent common issues like double-nested anchor tags or clobbering existing `href` attributes. Directly manipulating innerHTML or using other string replacement methods alongside Autolinker may lead to unexpected results.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Refactor custom linking logic to use the `replaceFn` option provided by `Autolinker` which offers a flexible way to modify generated links or even prevent linking for specific matches.","message":"The codebase was converted to TypeScript and now uses ES6 exports. Direct overriding of regular expressions by assigning to `Matcher.prototype` is no longer supported since v2, which may affect highly customized implementations.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"No direct fix within the library currently for this specific issue. Users dealing with text containing RTLO characters should implement external sanitization or validation if this is a critical concern, or monitor for future patches.","message":"Autolinker v3.16.2 reverted an attempted fix for Right-to-Left Override (RTLO) characters splitting links, meaning the library may not fully handle edge cases involving these characters and could result in improperly split links.","severity":"gotcha","affected_versions":"3.16.2"}],"env_vars":null,"search_vec":"'activ':50 'address':19 'altern':106 'anchor':121,150 'attribut':128 'auto':145 'autolink':147 'autolinker.js':1,2,107 'automat':10 'avoid':116 'backtrack':95 'base':102 'bug':65 'cadenc':52 'catastroph':94 'clickabl':38 'common':97 'content':137 'convert':13 'correct':112,139 'creation':118 'critic':143 'current':41 'design':8,110 'detect':11 'differenti':69 'email':18 'enhanc':63 'exist':126 'express':101 'expression-bas':100 'facebook':30 'finit':80 'fix':66 'focus':60 'frequent':53 'handl':113 'href':127 'html':36,114 'hyperlink':39 'improv':90 'inadvert':124 'input':115 'instagram':27 'issu':96 'javascript':6,144 'key':68 'librari':47 'like':16 'linear':86 'link':146 'machin':82 'maintain':48 'make':129 'mani':105 'media':24 'mentions/hashtags':25 'meticul':109 'minor':55 'modifi':125 'n':85 'nest':120 'number':21 'o':84 'often':59 'parser':74,103 'particular':131 'patch':57 'pattern':15 'perform':62,88,141 'phone':20 'plain':33 'prevent':93 'process':134 'publish':54 'regular':99 'releas':51 'rewritten':72 'rich':135 'robust':5 'signific':89 'social':23 'soundcloud':31 'speed':91 'stabl':42 'state':81 'suitabl':132 'tag':122 'text':34,136 'tiktok':29 'time':87 'twitter':26 'typescript':151 'unlik':104 'updat':58 'url':17,73,148,149 'util':7,78 'v4.0.0':76 'v4.1.5':45 'various':14 'version':43 'within':32 'youtub':28","created_at":"2026-04-19T13:33:15.961620+00:00","updated_at":"2026-04-19T13:33:15.961620+00:00","problems":[{"fix":"For CommonJS, use `const Autolinker = require('autolinker');`. For ESM, use `import Autolinker from 'autolinker';`. Ensure your project's `package.json` `\"type\"` field and `tsconfig.json` `module` and `moduleResolution` options are correctly configured for your environment (e.g., `\"type\": \"module\"` for ESM, `\"type\": \"commonjs\"` for CJS).","cause":"Attempting to `require()` Autolinker in a CommonJS environment while the package is treated as an ES Module, or vice versa, due to Node.js module resolution issues.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported"},{"fix":"Change the import statement to `import Autolinker from 'autolinker';` for ESM/TypeScript environments. For CommonJS, ensure `const Autolinker = require('autolinker');` is used.","cause":"Trying to instantiate `Autolinker` as a class (`new Autolinker()`) but it was imported incorrectly, often due to using a named import `import { Autolinker } from 'autolinker';` instead of the default import.","error":"TypeError: Autolinker is not a constructor"},{"fix":"For browsers, include the `Autolinker.min.js` script directly via a `<script>` tag, which exposes `Autolinker` globally. For Node.js, ensure your `package.json` contains `\"type\": \"module\"` or use a `.mjs` file extension, or revert to CommonJS `require()` syntax.","cause":"Using `import Autolinker from 'autolinker';` in a non-ES module browser environment or a Node.js script not configured as an ES module.","error":"Uncaught SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.4","cli_name":"","cli_version":null,"type":"library","homepage":"https://autolinker.io","github":"https://github.com/gregjacobs/Autolinker.js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/autolinker","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","communication","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}