diff --git a/types/linkify-it/index.d.ts b/types/linkify-it/index.d.ts new file mode 100644 index 0000000000..00b564bff6 --- /dev/null +++ b/types/linkify-it/index.d.ts @@ -0,0 +1,50 @@ +// Type definitions for tweezer.js 2.0 +// Project: https://github.com/markdown-it/linkify-it +// Definitions by: Lindsey Smith , Robert Coie +// 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; diff --git a/types/linkify-it/linkify-it-tests.ts b/types/linkify-it/linkify-it-tests.ts new file mode 100644 index 0000000000..c4366321cf --- /dev/null +++ b/types/linkify-it/linkify-it-tests.ts @@ -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'; + } +}); diff --git a/types/linkify-it/tsconfig.json b/types/linkify-it/tsconfig.json new file mode 100644 index 0000000000..d773912f34 --- /dev/null +++ b/types/linkify-it/tsconfig.json @@ -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" + ] +} diff --git a/types/linkify-it/tslint.json b/types/linkify-it/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/types/linkify-it/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file