Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/drop-ins.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
"entry": "tinylinkify",
"gzip": {
"theirs": 4211,
"ours": 1836
"ours": 1955
},
"parse": {
"theirs": 5.666320437499962,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Smaller, faster, dependency-free parsers and linkifiers you can drop in for the
| [tinyaml](./packages/tinyaml) | YAML | [7.7 KiB](./packages/tinyaml#size-and-speed) | js-yaml 4 and 5, yaml 2, yamljs, @std/yaml |
| [tinyjson5](./packages/tinyjson5) | JSON5 | [3.4 KiB](./packages/tinyjson5#size) | json5 2.2.3 |
| [tinyini](./packages/tinyini) | INI | [1.3 KiB](./packages/tinyini#size) | ini 1.3.8, 2 to 4.0 and 4.1.3 to 7, @one-ini/wasm 0.1.1 to 0.2 |
| [tinylinkify](./packages/tinylinkify) | Links in text | [1.8 KiB](./packages/tinylinkify#size) | linkify-it 4 and 5 |
| [tinylinkify](./packages/tinylinkify) | Links in text | [1.9 KiB](./packages/tinylinkify#size) | linkify-it 4 and 5 |

Bundle sizes include every export of each package's root API, minified and gzipped. See [Size and speed](#size-and-speed) for the drop-in replacements.

Expand Down
4 changes: 2 additions & 2 deletions docs/pages/tinylinkify/size-and-speed.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Each entry as npm ships it in `dist/`, bundled with esbuild, minified ESM, then

| Entry | Minified | Gzip |
| ------------------------ | --------- | -------- |
| `tinylinkify` | 3.55 KiB | 1.79 KiB |
| `tinylinkify/gfm` | 4.65 KiB | 2.22 KiB |
| `tinylinkify` | 3.87 KiB | 1.91 KiB |
| `tinylinkify/gfm` | 5.04 KiB | 2.37 KiB |
| `tinylinkify/linkify-it` | 10.32 KiB | 3.90 KiB |
| linkify-it 5.0.2 | 11.25 KiB | 4.11 KiB |
| linkify-it 6.1.0 | 13.30 KiB | 4.40 KiB |
Expand Down
10 changes: 5 additions & 5 deletions packages/tinylinkify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<!-- automd:comark-badges name=tinylinkify size=size -->

[![release](https://comark-ui.onmax.me/badge.svg?source=npm-version&package=tinylinkify&label=release&icon=npm)](https://github.com/onmax/tiny/releases)
[![size](https://comark-ui.onmax.me/badge.svg?label=size&value=1.8+KiB+gzip)](#size)
[![size](https://comark-ui.onmax.me/badge.svg?label=size&value=1.9+KiB+gzip)](#size)
[![dependencies](https://comark-ui.onmax.me/badge.svg?label=dependencies&value=0)](https://www.npmjs.com/package/tinylinkify?activeTab=dependencies)
[![license: MIT](https://comark-ui.onmax.me/badge.svg?label=license&value=MIT)](./LICENSE)
[![Release status](https://comark-ui.onmax.me/badge.svg?source=github-actions&repository=onmax%2Ftiny&workflow=release.yaml&icon=github)](https://github.com/onmax/tiny/actions/workflows/release.yaml)

<!-- /automd -->

**Links in plain text, in 1.8 KiB.** No dependencies, GFM's autolink rules as remark-gfm and GitHub apply them, and up to 3 times faster than linkify-it.
**Links in plain text, in 1.9 KiB.** No dependencies, GFM's autolink rules as remark-gfm and GitHub apply them, and up to 3 times faster than linkify-it.

Already on linkify-it? Change one import and keep your code:

Expand All @@ -29,7 +29,7 @@ tinylinkify ships a drop-in replacement for linkify-it 5 (and 4), and `tinylinki
| ---------------- | ------------------------ | ------------: | ----------: | ----------: |
| linkify-it 5.0.2 | `tinylinkify/linkify-it` | 4.1 → 3.9 KiB | 1.1× faster | — |

The root `tinylinkify` API, which finds GFM links, is 1.8 KiB against 4.1 KiB for linkify-it 5.0.2, and finds them 2.8× faster than linkify-it finds its own in the same text.
The root `tinylinkify` API, which finds GFM links, is 1.9 KiB against 4.1 KiB for linkify-it 5.0.2, and finds them 2.8× faster than linkify-it finds its own in the same text.

Size is the minified bundle, gzipped. Speed is the median time to parse and stringify the large benchmark file. linkify-it only finds links, so its time is `match` on 100 KB of text. Measured on AMD Ryzen 7 255 w/ Radeon 780M Graphics, Node 24.21.0.

Expand Down Expand Up @@ -138,8 +138,8 @@ Each entry as npm ships it in `dist/`, bundled with esbuild, minified ESM, then

| Entry | Minified | Gzip |
| ------------------------ | --------- | -------- |
| `tinylinkify` | 3.55 KiB | 1.79 KiB |
| `tinylinkify/gfm` | 4.65 KiB | 2.22 KiB |
| `tinylinkify` | 3.87 KiB | 1.91 KiB |
| `tinylinkify/gfm` | 5.04 KiB | 2.37 KiB |
| `tinylinkify/linkify-it` | 10.32 KiB | 3.90 KiB |
| linkify-it 5.0.2 | 11.25 KiB | 4.11 KiB |
| linkify-it 6.1.0 | 13.30 KiB | 4.40 KiB |
Expand Down
4 changes: 2 additions & 2 deletions packages/tinylinkify/scripts/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const entries: [string, string, string?][] = [
// Gzip bytes each entry may reach, about 30 over its size when last set.
// Raise one on purpose, and say why in the commit.
const BUDGET: Record<string, number> = {
tinylinkify: 1870,
"tinylinkify/gfm": 2300,
tinylinkify: 1985,
"tinylinkify/gfm": 2460,
"tinylinkify/linkify-it": 4030,
};

Expand Down
8 changes: 5 additions & 3 deletions packages/tinylinkify/src/core/gfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ function protocol(i: number): [string, number] | undefined {

// mdast-util-gfm-autolink-literal's searches, in its order.
const URL = /(?<![\da-z])(https?:\/\/|www(?=\.))([\w-]*\.[\w\-.]*)/gi;
// Without `www.` links: a `www` match it would turn down anyway, after
// reading the rest of its host.
const HTTP = /(?<![\da-z])(https?:\/\/)([\w-]*\.[\w\-.]*)/gi;
const XMPP =
/(?<![\w+\-.@])xmpp:([\w+\-.]+)@([\w-]+(?:\.[\w-]+)+)(\/(?:[\w\-/]|\.(?=[\dA-Za-z]))*)?/g;
const MAILTO = /(?<![\w+\-.@])mailto:([\w+\-.]+)@([\w-]+(?:\.[\w-]+)+)/g;
Expand Down Expand Up @@ -226,7 +229,7 @@ export function find(value: string, www = true, email = true, first = false): Li
// character.
const needs = [hasScheme || hasWww, value.includes("xmpp:"), value.includes("mailto:"), hasAt];
for (let s = 0; s < 4; s++) {
const search = SEARCHES[s]!;
const search = s ? SEARCHES[s]! : www ? URL : HTTP;
if (!needs[s]) continue;
links.sort((a, b) => a.index - b.index);
const gaps: number[] = [];
Expand All @@ -245,7 +248,7 @@ export function find(value: string, www = true, email = true, first = false): Li
const [whole, a = "", b = "", rest] = m;
let retry = m.index + 1;
let ok = !/[\d\-_]$/.test(b);
if (search === URL) {
if (!s) {
const c = run.charCodeAt(m.index - 1);
let host = b;
let scheme = a;
Expand All @@ -258,7 +261,6 @@ export function find(value: string, www = true, email = true, first = false): Li
const labels = host.split(".");
ok =
(!m.index || whitespace(c) || punctuation(c)) &&
(www || !prefix) &&
!punctuation(host.charCodeAt(0)) &&
labels.length > 1 &&
!badLabel(labels.at(-1)) &&
Expand Down
9 changes: 9 additions & 0 deletions packages/tinylinkify/test/gfm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ describe("tinylinkify/gfm", () => {
expect(performance.now() - start).toBeLessThan(1000);
});

it("doesn't read the rest of a domain at each www with fuzzyLink off", () => {
const text = `:// ${"www._".repeat(16_000)}.a.b https://example.com`;
const start = performance.now();
expect(new LinkifyIt({ fuzzyLink: false }).match(text)?.at(-1)?.url).toBe(
"https://example.com",
);
expect(performance.now() - start).toBeLessThan(500);
});

it("is a plugin that turns linkify on, with its options", () => {
const md = createMarkdownExit().use(linkifyGfm, { fuzzyEmail: false });
expect(md.render("see www.example.com, mail a.b@example.com")).toBe(
Expand Down
Loading