Add types for linkify-it

This commit is contained in:
Lindsey Smith
2017-03-29 14:04:44 -04:00
parent 930230f4de
commit d679f337ee
4 changed files with 97 additions and 0 deletions

50
types/linkify-it/index.d.ts vendored Normal file
View File

@@ -0,0 +1,50 @@
// Type definitions for tweezer.js 2.0
// 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, options?: LinkifyIt.Options): LinkifyIt.LinkifyIt;
new (schemas?: LinkifyIt.SchemaRules, options?: LinkifyIt.Options): LinkifyIt.LinkifyIt;
};
declare namespace LinkifyIt {
export interface FullRule {
validate: (text: string, pos: number, self: LinkifyIt) => number;
normalize?: (match: string) => string;
}
export type Rule = string | RegExp | FullRule;
export interface SchemaRules {
[schema: string]: Rule;
}
export interface Options {
fuzzyLink?: boolean;
fuzzyIP?: boolean;
fuzzyEmail?: boolean;
}
export interface Match {
index: number;
lastIndex: number;
raw: string;
schema: string;
text: string;
url: string;
}
export 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;

View File

@@ -0,0 +1,24 @@
import LinkifyIt = require('linkify-it');
// fluent interface
const linkifier = new LinkifyIt();
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';
}
});

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"linkify-it-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "../tslint.json" }