mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-04-04 20:54:36 +00:00
* the constructor accepts as first parameter or the SchemaRules or the Options * the validate callback can be either a string, RegExp or Validate type * Rule only accepts a string or a FullRule, where when a string is set, it applies the same rules as the given schema name * add more tests to showcase and type test the implementation
49 lines
1019 B
TypeScript
49 lines
1019 B
TypeScript
import LinkifyIt = require("linkify-it");
|
|
|
|
// constructor formats
|
|
const linkifier = new LinkifyIt();
|
|
const withOptions = new LinkifyIt({ fuzzyLink: false });
|
|
const withSchema = new LinkifyIt(
|
|
{
|
|
"myCustom:": {
|
|
validate: /23/
|
|
},
|
|
"other:": {
|
|
validate: (text, pos, self) => 42
|
|
},
|
|
"git:": "http:"
|
|
},
|
|
{
|
|
fuzzyIP: false,
|
|
fuzzyLink: false
|
|
}
|
|
);
|
|
|
|
// fluent interface
|
|
linkifier
|
|
.add("git:", "http:")
|
|
.set({ fuzzyIP: true })
|
|
.tlds("onion", true)
|
|
.test("https://github.com/DefinitelyTyped/DefinitelyTyped/");
|
|
|
|
// match
|
|
const matches = linkifier.match(
|
|
"https://github.com/DefinitelyTyped/DefinitelyTyped/"
|
|
);
|
|
matches.forEach(({ index, lastIndex, raw, schema, text, url }) => {});
|
|
|
|
// complex rule
|
|
linkifier.add("@", {
|
|
validate: (text, pos, self) => {
|
|
return 42;
|
|
},
|
|
normalize: match => {
|
|
return "forty-two";
|
|
}
|
|
});
|
|
|
|
// regexp rule
|
|
linkifier.add("custom:", {
|
|
validate: /^\/\/\d+/
|
|
});
|