Skip to content

Releases: alexcorvi/anchorme.js

2.1.1

08 May 13:08
Compare
Choose a tag to compare

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

  • Fixed bug where the library doesn't count slashes at the end. (#71)
  • Fixed a bug where the library breaks HTML if a non-standard attribute had a link (#76 #72).
  • Fixed a bug where the library breaks inline styling if it had a link (#75)

2.0.0

03 Apr 21:16
Compare
Choose a tag to compare

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

06 Apr 01:36
Compare
Choose a tag to compare
  • Fixed: protocol being removed twice before counting slashes

1.1.1

06 Apr 01:23
Compare
Choose a tag to compare
  • Fix #47 (fixed having an extra file:/// protocol)

1.1.0

05 Apr 11:00
Compare
Choose a tag to compare
  • Fixed #46
  • Added ability to exclude URLs for any reason via custom exclusion function. (docs)

1.0.4

03 Mar 08:37
Compare
Choose a tag to compare
  • Rebuild and fix minor case sensitivity issue.

0.6.0

02 Mar 07:17
Compare
Choose a tag to compare
0.6.0 Pre-release
Pre-release

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.

1.0.3

03 Mar 08:23
Compare
Choose a tag to compare

1.0.2

28 Feb 14:57
Compare
Choose a tag to compare

1.0.1

26 Feb 21:22
Compare
Choose a tag to compare
  • Compiled to ES5 fixed #33