diff --git a/types/wordpress__autop/index.d.ts b/types/wordpress__autop/index.d.ts new file mode 100644 index 0000000000..6b3d8720ac --- /dev/null +++ b/types/wordpress__autop/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for @wordpress/autop 2.3 +// Project: https://github.com/WordPress/gutenberg/tree/master/packages/autop/README.md +// Definitions by: Derek Sifford +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.4 + +/** + * Replaces double line-breaks with paragraph elements. + * + * @remarks + * A group of regex replaces used to identify text formatted with newlines and + * replace double line-breaks with HTML paragraph tags. The remaining line- + * breaks after conversion become `
` tags, unless br is set to 'false'. + * + * @example + * ```js + * import { autop } from '@wordpress/autop'; + * autop( 'my text' ); // "

my text

" + * ``` + * + * @param text - The text which has to be formatted. + * @param br - Optional. If set, will convert all remaining line- breaks + * after paragraphing. Default `true`. + * + * @returns Text which has been converted into paragraph tags. + */ +export function autop(text: string, br?: boolean): string; + +/** + * Replaces `

` tags with two line breaks. "Opposite" of autop(). + * + * @remarks + * Replaces `

` tags with two line breaks except where the `

` has attributes. + * Unifies whitespace. Indents `

  • `, `
    ` and `
    ` for better readability. + * + * @example + * ```js + * import { removep } from '@wordpress/autop'; + * removep( '

    my text

    ' ); // "my text" + * ``` + * @param html - The content from the editor. + * + * @returns The content with stripped paragraph tags. + */ +export function removep(html: string): string; diff --git a/types/wordpress__autop/tsconfig.json b/types/wordpress__autop/tsconfig.json new file mode 100644 index 0000000000..0965546cf8 --- /dev/null +++ b/types/wordpress__autop/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "@wordpress/autop": ["wordpress__autop"] + } + }, + "files": ["index.d.ts", "wordpress__autop-tests.ts"] +} diff --git a/types/wordpress__autop/tslint.json b/types/wordpress__autop/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wordpress__autop/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wordpress__autop/wordpress__autop-tests.ts b/types/wordpress__autop/wordpress__autop-tests.ts new file mode 100644 index 0000000000..307e84f406 --- /dev/null +++ b/types/wordpress__autop/wordpress__autop-tests.ts @@ -0,0 +1,5 @@ +import { autop, removep } from '@wordpress/autop'; + +autop('my text'); // "

    my text

    " + +removep('

    my text

    '); // "my text"