diff --git a/packages/escape-html/CHANGELOG.md b/packages/escape-html/CHANGELOG.md index 2562662aa2ce91..2a6282c050c8fc 100644 --- a/packages/escape-html/CHANGELOG.md +++ b/packages/escape-html/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Internal + +- Refactor to TypeScript ([#62586](https://github.com/WordPress/gutenberg/pull/62586)). + ## 3.0.0 (2024-05-31) ### Breaking Changes diff --git a/packages/escape-html/src/escape-greater.js b/packages/escape-html/src/escape-greater.ts similarity index 68% rename from packages/escape-html/src/escape-greater.js rename to packages/escape-html/src/escape-greater.ts index f761a81e16ae61..6e5956dc47e8f3 100644 --- a/packages/escape-html/src/escape-greater.js +++ b/packages/escape-html/src/escape-greater.ts @@ -6,10 +6,10 @@ * * See: https://core.trac.wordpress.org/ticket/45387 * - * @param {string} value Original string. + * @param value Original string. * - * @return {string} Escaped string. + * @return Escaped string. */ -export default function __unstableEscapeGreaterThan( value ) { +export default function __unstableEscapeGreaterThan( value: string ): string { return value.replace( />/g, '>' ); } diff --git a/packages/escape-html/src/index.js b/packages/escape-html/src/index.ts similarity index 72% rename from packages/escape-html/src/index.js rename to packages/escape-html/src/index.ts index 8ddce62c443257..71206695bb7d3b 100644 --- a/packages/escape-html/src/index.js +++ b/packages/escape-html/src/index.ts @@ -11,10 +11,9 @@ import __unstableEscapeGreaterThan from './escape-greater'; * and noncharacters." * * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 - * - * @type {RegExp} */ -const REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/; +const REGEXP_INVALID_ATTRIBUTE_NAME: RegExp = + /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/; /** * Returns a string with ampersands escaped. Note that this is an imperfect @@ -26,33 +25,33 @@ const REGEXP_INVALID_ATTRIBUTE_NAME = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/; * @see https://w3c.github.io/html/syntax.html#ambiguous-ampersand * @see https://w3c.github.io/html/syntax.html#named-character-references * - * @param {string} value Original string. + * @param value Original string. * - * @return {string} Escaped string. + * @return Escaped string. */ -export function escapeAmpersand( value ) { +export function escapeAmpersand( value: string ): string { return value.replace( /&(?!([a-z0-9]+|#[0-9]+|#x[a-f0-9]+);)/gi, '&' ); } /** * Returns a string with quotation marks replaced. * - * @param {string} value Original string. + * @param value Original string. * - * @return {string} Escaped string. + * @return Escaped string. */ -export function escapeQuotationMark( value ) { +export function escapeQuotationMark( value: string ): string { return value.replace( /"/g, '"' ); } /** * Returns a string with less-than sign replaced. * - * @param {string} value Original string. + * @param value Original string. * - * @return {string} Escaped string. + * @return Escaped string. */ -export function escapeLessThan( value ) { +export function escapeLessThan( value: string ): string { return value.replace( / string; + +function testUnstableEscapeGreaterThan( implementation: Implementation ) { it( 'should escape greater than', () => { const result = implementation( 'Chicken > Ribs' ); expect( result ).toBe( 'Chicken > Ribs' ); } ); } -function testEscapeAmpersand( implementation ) { +function testEscapeAmpersand( implementation: Implementation ) { it( 'should escape ampersand', () => { const result = implementation( 'foo & bar & & baz Σ &#bad; Σ Σ vil;' @@ -31,7 +33,7 @@ function testEscapeAmpersand( implementation ) { } ); } -function testEscapeQuotationMark( implementation ) { +function testEscapeQuotationMark( implementation: Implementation ) { it( 'should escape quotation mark', () => { const result = implementation( '"Be gone!"' ); @@ -39,7 +41,7 @@ function testEscapeQuotationMark( implementation ) { } ); } -function testEscapeLessThan( implementation ) { +function testEscapeLessThan( implementation: Implementation ) { it( 'should escape less than', () => { const result = implementation( 'Chicken < Ribs' );