Skip to content

Commit 7202eec

Browse files
committed
Build 4.1.5
1 parent e2011f1 commit 7202eec

File tree

12 files changed

+1017
-1011
lines changed

12 files changed

+1017
-1011
lines changed

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,29 @@ So, this utility attempts to handle everything. It:
2929
In other words, it will automatically link the text "google.com", as well as
3030
"http://google.com". Will also autolink IPv4 addresses.
3131
- Will properly handle URLs with query params, anchors,
32-
and special characters, and not include things like a trailing `.` at the end
32+
and special characters, and not include chars like a trailing `.` at the end
3333
of a sentence, or a `)` char if the URL is inside parenenthesis.
3434
- Will autolink email addresses
3535
- Will autolink phone numbers
3636
- Will autolink mentions (Twitter, Instagram, Soundcloud, TikTok, Youtube)
3737
- Will autolink hashtags (Twitter, Instagram, Facebook, TikTok, Youtube)
38+
- Won't clobber URLs with hash anchors by treating them as hashtags (like some other libraries do). For example: `google.com/#anchor` is properly linked.
3839
- **Will properly handle HTML input.** The utility will not overwrite an `href`
3940
attribute inside anchor (`<a>`) tags (or any other tag/attribute), and will not
4041
accidentally wrap the inner text of `<a>`/`<script>`/`<style>` tags with a new
4142
one (which cause doubly-nested anchor tags, or mess with scripts)
42-
- Will do all of this in `O(n)` (linear) time with low constant factors and
43-
without the possibility of RegExp backtracking, making it extremely fast.
43+
- Will do all of this in `O(n)` (linear) time with low constant factors and without the possibility of RegExp [Catastrophic Backtracking](https://www.regular-expressions.info/catastrophic.html), making it extremely fast and unsusceptible to pathological inputs.
44+
45+
<a name="benchmarks-table"></a>Quick [benchmarks](#benchmarks) comparison:
46+
47+
| Library | Ops/Sec | MOE | Compared to Fastest |
48+
| ----------------------------------- | ------- | ------ | --------------------|
49+
| **Autolinker**@4.1.5 | 3,278 | ±0.40% | Fastest ✅ |
50+
| [anchorme][1]@3.0.8 | 2,393 | ±0.35% | 26% (1.37x) slower |
51+
| [linkifyjs][2]@4.2.0 (linkify-html) | 1,875 | ±0.32% | 42% (1.75x) slower |
52+
| [linkify-it][3]@5.0.0 | 491 | ±0.54% | 85% (6.67x) slower |
53+
54+
(please let me know of other comparable libraries to compare to!)
4455

4556
Hope that this utility helps you as well!
4657

@@ -130,7 +141,7 @@ const autolinker = new Autolinker([ options ]);
130141
const linkedText = autolinker.link(textToAutoLink);
131142
```
132143

133-
Note: if using the same options to autolink multiple pieces of html/text, it is
144+
Note: if using the same options to autolink multiple pieces of html/text, it's
134145
slightly more efficient to create a single Autolinker instance, and run the
135146
[link()](http://gregjacobs.github.io/Autolinker.js/api/#!/api/Autolinker-method-link)
136147
method repeatedly (i.e. use the "class" form above).
@@ -580,14 +591,21 @@ Then open your browser to: http://localhost:8080/docs/examples/index.html
580591
You should be able to make a change to source files, and refresh the page to see
581592
the changes.
582593
583-
#### Running the benchmarks
594+
#### Running the benchmarks <a name="benchmarks"></a>
584595
585596
Run:
586597
587598
```sh
588599
pnpm run benchmarks
589600
```
590601
602+
> Note: See the [Benchmarks Table](#benchmarks-table) above for current results.
603+
604+
Couple points on the benchmarks:
605+
* These benchmarks attempt to set up all libraries by configuring comparable features to Autolinker (e.g.: linking emails, hashtags, mentions, etc.) to try to get an apples-to-apples comparison.
606+
* While developing, recommend running the benchmarks a few times both before and after making any changes if developing.
607+
* See the [benchmarks](./benchmarks) folder and [benchmarks/input-text.ts](./benchmarks/input-text.ts) for how the benchmarks are set up and what input they are given.
608+
591609
#### Documentation Generator Notes
592610
593611
This project uses [JSDuck](https://github.com/senchalabs/jsduck) for its
@@ -636,3 +654,9 @@ instructions on Windows/Mac/Linux.
636654
## Changelog
637655

638656
See [Releases](https://github.com/gregjacobs/Autolinker.js/releases)
657+
658+
<!-- Reference Links -->
659+
660+
[1]: https://github.com/alexcorvi/anchorme.js "anchorme.js"
661+
[2]: https://linkify.js.org/docs/linkify-html.html "linkify-html"
662+
[3]: https://github.com/markdown-it/linkify-it "linkify-it"

benchmarks/anchorme-3.0.8/index.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
import anchorme from 'anchorme';
22
import { inputText } from '../input-text';
33

4-
console.log(anchorme(inputText));
4+
// Try to set up anchorme with roughly the same features as Autolinker
5+
const options = {
6+
input: inputText,
7+
options: {
8+
attributes: {
9+
target: '_blank',
10+
class: 'detected',
11+
},
12+
},
13+
extensions: [
14+
// hashtag search
15+
{
16+
test: /#(\w|_)+/gi,
17+
transform: (string: string) =>
18+
`<a href="https://a.b?s=${string.substring(1)}">${string}</a>`,
19+
},
20+
// mentions
21+
{
22+
test: /@(\w|_)+/gi,
23+
transform: (string: string) =>
24+
`<a href="https://a.b/${string.substring(1)}">${string}</a>`,
25+
},
26+
],
27+
};
28+
29+
// console.log('input text: ', inputText);
30+
// console.log('output: ', anchorme(options)); // seems anchorme.js@3.0.8 gets confused between #anchors in URLs and hashtags
531

632
export function runAnchorMe3_0_8() {
7-
anchorme({
8-
input: inputText,
9-
options: {
10-
attributes: {
11-
target: '_blank',
12-
class: 'detected',
13-
},
14-
},
15-
extensions: [
16-
// an extension for hashtag search
17-
{
18-
test: /#(\w|_)+/gi,
19-
transform: string => `<a href="https://a.b?s=${string.substring(1)}">${string}</a>`,
20-
},
21-
// an extension for mentions
22-
{
23-
test: /@(\w|_)+/gi,
24-
transform: string => `<a href="https://a.b/${string.substring(1)}">${string}</a>`,
25-
},
26-
],
27-
});
33+
anchorme(options);
2834
}

benchmarks/benchmarks.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
import Benchmark from 'benchmark';
22
import CliTable from 'cli-table';
33

4+
// Autolinker benchmarks
45
import { runAutolinkerCurrent } from './autolinker-current/index';
5-
import { runAutolinker4_1_3 } from './autolinker-4.1.3/index';
6+
// import { runAutolinker4_1_3 } from './autolinker-4.1.3/index';
67
// import { runAutolinker4_1_2 } from './autolinker-4.1.2/index';
78
// import { runAutolinker4_0_0 } from './autolinker-4.0.0/index';
89
// import { runAutolinker3_16_2 } from './autolinker-3.16.2/index';
910
// import { runAutolinker2_2_2 } from './autolinker-2.2.2/index';
1011
// import { runAutolinker1_8_3 } from './autolinker-1.8.3/index';
12+
13+
// Other library benchmarks
1114
import { runAnchorMe3_0_8 } from './anchorme-3.0.8/index';
1215
import { runLinkifyIt5_0_0 } from './linkify-it-5.0.0/index';
13-
import { runLinkifyJsHtml4_2_0 /*, runLinkifyJsString4_2_0*/ } from './linkifyjs-4.2.0/index';
16+
import { runLinkifyJsHtml4_2_0 } from './linkifyjs-4.2.0/index';
1417

1518
const suite = new Benchmark.Suite();
1619

1720
// add tests
1821
suite
22+
// Autolinker benchmarks
1923
.add('autolinker@current-src', runAutolinkerCurrent)
20-
.add('autolinker@4.1.3', runAutolinker4_1_3)
24+
// .add('autolinker@4.1.3', runAutolinker4_1_3)
2125
// .add('autolinker@4.1.2', runAutolinker4_1_2)
2226
// .add('autolinker@4.0.0', runAutolinker4_0_0)
2327
// .add('autolinker@3.16.2', runAutolinker3_16_2)
2428
// .add('autolinker@2.2.2', runAutolinker2_2_2)
2529
// .add('autolinker@1.8.3', runAutolinker1_8_3)
30+
31+
// Other libraries benchmarks
2632
.add('anchorme@3.0.8', runAnchorMe3_0_8)
2733
.add('linkify-it@5.0.0', runLinkifyIt5_0_0)
2834
.add('linkifyjs@4.2.0 (linkify-html)', runLinkifyJsHtml4_2_0)
29-
// .add('linkifyjs@4.2.0 (linkify-string)', runLinkifyJsString4_2_0)
3035

3136
.on('cycle', (event: Benchmark.Event) => {
3237
console.log(String(event.target));

benchmarks/shared-autolinker-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export const sharedAutolinkerConfig = {
55
email: true,
66
mention: 'twitter',
77
hashtag: 'twitter',
8-
// phone: true, -- linkifyjs is the closest in performance to autolinker but doesn't support phone numbers
8+
// phone: true, -- anchorme.js and linkifyjs are the closest in performance to Autolinker, but neither support phone numbers
99
} as const; // as const to make this config object compatible between the most versions rather than using a specific version's AutolinkerConfig type

0 commit comments

Comments
 (0)