-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
219 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
import { LinkifyOptions } from "./index"; | ||
import { Options as CommonOptions, LinkEntityType } from './index'; | ||
|
||
export function linkifyElement(element: HTMLElement, options?: LinkifyOptions, doc?: HTMLDocument): HTMLElement; | ||
export default linkifyElement; | ||
export interface Options extends CommonOptions { | ||
/** | ||
* Add event listeners to newly created link elements. | ||
* Takes a hash where each key is an standard event name and the value is an event handler. | ||
* | ||
* Also accepts a function that takes the unformatted href and the link type (e.g., 'url', 'email', etc.) and returns the hash. | ||
* | ||
* @default null | ||
*/ | ||
events?: Partial<GlobalEventHandlers> | ((href: string, type: LinkEntityType) => Partial<GlobalEventHandlers>); | ||
|
||
/** | ||
* Prevent linkify from trying to parse links in the specified tags. | ||
* | ||
* This is useful when running linkify on arbitrary HTML. | ||
* | ||
* @default [] | ||
*/ | ||
ignoreTags?: string[]; | ||
} | ||
|
||
export default function linkifyElement(element: HTMLElement, options?: Options, doc?: HTMLDocument): HTMLElement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
import { LinkifyOptions } from "./index"; | ||
import { Options as CommonOptions, LinkEntityType } from './index'; | ||
|
||
export function linkifyHtml(input: string, options?: LinkifyOptions): string; | ||
export default linkifyHtml; | ||
export interface Options extends CommonOptions { | ||
/** | ||
* Add event listeners to newly created link elements. | ||
* Takes a hash where each key is an standard event name and the value is an event handler. | ||
* | ||
* Also accepts a function that takes the unformatted href and the link type (e.g., 'url', 'email', etc.) and returns the hash. | ||
* | ||
* @default null | ||
*/ | ||
events?: Partial<GlobalEventHandlers> | ((href: string, type: LinkEntityType) => Partial<GlobalEventHandlers>); | ||
|
||
/** | ||
* Prevent linkify from trying to parse links in the specified tags. | ||
* | ||
* This is useful when running linkify on arbitrary HTML. | ||
* | ||
* @default [] | ||
*/ | ||
ignoreTags?: string[]; | ||
} | ||
|
||
export default function linkifyHtml(input: string, options?: Options): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as Linkify from 'linkifyjs'; | ||
|
||
Linkify.find(); // $ExpectError | ||
Linkify.find(1); // $ExpectError | ||
Linkify.find('my string', 1); // $ExpectError | ||
Linkify.find('my string'); // $ExpectType FindResultHash[] | ||
Linkify.find('my string', 'email'); // $ExpectType FindResultHash[] | ||
Linkify.find('my string', 'hashtag'); // $ExpectType FindResultHash[] | ||
Linkify.find('my string', 'my type'); // $ExpectError | ||
|
||
Linkify.test(); // $ExpectError | ||
Linkify.test(1); // $ExpectError | ||
Linkify.test('my string', 1); // $ExpectError | ||
Linkify.test('my string'); // $ExpectType boolean | ||
Linkify.test('my string', 'email'); // $ExpectType boolean | ||
Linkify.test('my string', 'hashtag'); // $ExpectType boolean | ||
Linkify.test('my string', 'my type'); // $ExpectError | ||
|
||
Linkify.tokenize(); // $ExpectError | ||
Linkify.tokenize(1); // $ExpectError | ||
Linkify.tokenize('my string'); // $ExpectType { v: { v: string; }[]; }[] | ||
|
||
let options: Linkify.Options; | ||
|
||
options = {}; // $ExpectType {} | ||
options = { attributes: null }; // $ExpectType { attributes: null; } | ||
options = { attributes: 'hello-world' }; // $ExpectError | ||
options = { attributes: { attr: 'hello-world' } }; // $ExpectType { attributes: { attr: string; }; } | ||
options = { attributes: href => ({}) }; // $ExpectType { attributes: (href: string) => {}; } | ||
|
||
options = { className: null }; // $ExpectError | ||
options = { className: 'new-link--url' }; // $ExpectType { className: string; } | ||
options = { className: (href, type) => `new-link-${type}` }; // $ExpectType { className: (href: string, type: LinkEntityType) => string; } | ||
options = { className: { sunshine: v => v } }; // $ExpectError | ||
options = { className: { email: () => 'new-link--email' } }; // $ExpectType { className: { email: () => string; }; } | ||
|
||
options = { defaultProtocol: null }; // $ExpectError | ||
options = { defaultProtocol: 1 }; // $ExpectError | ||
options = { defaultProtocol: 'http' }; // $ExpectType { defaultProtocol: string; } | ||
options = { defaultProtocol: 'ftp' }; // $ExpectType { defaultProtocol: string; } | ||
|
||
options = { format: null }; // $ExpectType { format: null; } | ||
options = { format: value => value }; // $ExpectType { format: (value: string) => string; } | ||
options = { format: { sunshine: v => v } }; // $ExpectError | ||
options = { format: { email: () => 'sunshine' } }; // $ExpectType { format: { email: () => string; }; } | ||
|
||
options = { formatHref: null }; // $ExpectType { formatHref: null; } | ||
options = { formatHref: href => href }; // $ExpectType { formatHref: (href: string) => string; } | ||
options = { formatHref: { sunshine: v => v } }; // $ExpectError | ||
options = { formatHref: { email: () => 'sunshine' } }; // $ExpectType { formatHref: { email: () => string; }; } | ||
|
||
options = { nl2br: 1 }; // $ExpectError | ||
options = { nl2br: true }; // $ExpectType { nl2br: true; } | ||
|
||
options = { tagName: null }; // $ExpectError | ||
options = { tagName: 'span' }; // $ExpectType { tagName: string; } | ||
|
||
options = { target: null }; // $ExpectError | ||
options = { target: '_parent' }; // $ExpectType { target: string; } | ||
|
||
options = { validate: null }; // $ExpectType { validate: null; } |
Oops, something went wrong.