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.
npm install autolinkerVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
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.
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).Change the import statement to `import Autolinker from 'autolinker';` for ESM/TypeScript environments. For CommonJS, ensure `const Autolinker = require('autolinker');` is used.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.
No dependency data recorded yet.