Releases: alexcorvi/anchorme.js
2.1.1
Improvements & New features
- The
list
options is exposing a lot more information about the listed token. - conditional options (those options parameters that passes a function as the value) are receiving a second argument now, exposing a lot more information about the token.
// for all tokens
export interface BaseTokenProps {
start: number;
end: number;
string: string;
reason: string; // could be "url", "email", "file"
}
// for emails tokens
export interface Email extends BaseTokenProps {
isEmail: true;
protocol: string;
local: string;
host: string;
}
// for URL token
export interface URL extends BaseTokenProps {
isURL: true;
protocol: string;
host: string;
port: string;
ipv4: string;
ipv6: string;
confirmedByProtocol: boolean;
path: string;
query: string;
fragment: string;
}
// for file tokens
export interface File extends BaseTokenProps {
isFile: true;
filename: string;
filePath: string;
fileDirectory: string;
}
Bug fixes
2.0.0
Anchorme 2.0
A complete rewrite, for better, faster, more accurate linking.
Introdution
Although development has stalled on this library, and that was largely due to design mistakes that I made when writing this library, I took advantage of the COVID-19 curfew and rewrote the whole library.
In all of the previous versions of this library I tried to avoid, as much as possible, regular expressions, and only used them when necessary, token validation. Anchorme 2.0 embraces regular expression and use them for everything, tokenization, lookup, validation, categorization... etc. Infact, the whole library can be summed up in one file regex.ts, and you can see that in line 23, there's a regular expression called finalRegex
, well, this is the heart of the library.
Extending
Extending the library is now possible, so you can add support for hashtags and mentions...etc.
Bug fixes
This release fixes 99% of the open issues that were for the previous versions.
Performance
As for performance, relying only on one optimized regular expression gave the library a pretty good advantage. And it is now faster than ever (checkout the benchmark).
Breaking changes
Previous versions suffered from a poorly designed API, so everything has been changes, here's a quick look on how to use the new version, for more details have a look at the documentation.
// If you're using NPM/Yarn, then you need
// to require the library first
const anchorme = require("anchorme").default; // like this
import anchorme from "anchorme"; // or this
// the library will export a single function
// that you can use like the examples below
const input = "some text with a link.com";
const resultA = anchorme(input);
const resultB = anchorme({ input });
const resultC = anchorme({
input,
// use some options
options: {
attributes: {
target: "_blank",
class: "detected",
},
},
// and extensions
extensions: [
// an extension for hashtag search
{
test: /#(\w|_)+/gi,
transform: (string) =>
`<a href="https://a.b?s=${string.substr(1)}">${string}</a>`,
},
// an extension for mentions
{
test: /@(\w|_)+/gi,
transform: (string) =>
`<a href="https://a.b/${string.substr(1)}">${string}</a>`,
},
],
});
1.1.2
1.1.1
1.1.0
1.0.4
0.6.0
What's new
The library has been re-written to be more efficient, more maintainable, and less buggy. Many enhancements and bug fixes were applied.
Fixed bugs:
- not having to enter spaces after the URL if an HTML element comes right after it. For example:
<p>www.google.com</p>
should be working now. - HTML won't break if there's a URL inside on of the element's attributes.
- Domain URLs are more sensitive.
Enhancements:
- Better comments, more readable code.
- Options object to configure the library and how it should work for you.
- Some performance concerns addressed and fixed.