mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 20:39:17 +08:00
Add types for linkify-it
This commit is contained in:
50
types/linkify-it/index.d.ts
vendored
Normal file
50
types/linkify-it/index.d.ts
vendored
Normal 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;
|
||||
24
types/linkify-it/linkify-it-tests.ts
Normal file
24
types/linkify-it/linkify-it-tests.ts
Normal 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';
|
||||
}
|
||||
});
|
||||
22
types/linkify-it/tsconfig.json
Normal file
22
types/linkify-it/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/linkify-it/tslint.json
Normal file
1
types/linkify-it/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user