Files
DefinitelyTyped/types/linkify-it/index.d.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

59 lines
1.6 KiB
TypeScript

// Type definitions for linkify-it 2.0.3
// Project: https://github.com/markdown-it/linkify-it
// Definitions by: Lindsey Smith <https://github.com/praxxis>, Robert Coie <https://github.com/rapropos/typed-linkify-it>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare const LinkifyIt: {
(
schemas?: LinkifyIt.SchemaRules | LinkifyIt.Options,
options?: LinkifyIt.Options
): LinkifyIt.LinkifyIt;
new (
schemas?: LinkifyIt.SchemaRules | LinkifyIt.Options,
options?: LinkifyIt.Options
): LinkifyIt.LinkifyIt;
};
declare namespace LinkifyIt {
type Validate = (text: string, pos: number, self: LinkifyIt) => number;
interface FullRule {
validate: string | RegExp | Validate;
normalize?(match: string): string;
}
type Rule = string | FullRule;
interface SchemaRules {
[schema: string]: Rule;
}
interface Options {
fuzzyLink?: boolean;
fuzzyIP?: boolean;
fuzzyEmail?: boolean;
}
interface Match {
index: number;
lastIndex: number;
raw: string;
schema: string;
text: string;
url: string;
}
interface LinkifyIt {
add(schema: string, rule: Rule): LinkifyIt;
match(text: string): Match[];
normalize(raw: string): string;
pretest(text: string): boolean;
set(options: Options): LinkifyIt;
test(text: string): boolean;
testSchemaAt(text: string, schemaName: string, pos: number): number;
tlds(list: string | string[], keepOld?: boolean): LinkifyIt;
}
}
export = LinkifyIt;