Files
DefinitelyTyped/types/linkify-it/linkify-it-tests.ts
Hendrik Schaeidt 589a7cff21 linkify-it: fix typings to reflect the api (#25102)
* 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
2018-04-18 12:34:35 -07:00

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+/
});