From 92098e23eb881ab7ff132616b8cb5a7826820f78 Mon Sep 17 00:00:00 2001 From: Reda Al Sulais Date: Fri, 11 Aug 2023 20:54:39 +0300 Subject: [PATCH] convert `svgDrawCommon` to TS --- .../common/{common.spec.js => common.spec.ts} | 24 +++++++++---------- .../{svgDrawCommon.js => svgDrawCommon.ts} | 9 +++---- 2 files changed, 17 insertions(+), 16 deletions(-) rename packages/mermaid/src/diagrams/common/{common.spec.js => common.spec.ts} (76%) rename packages/mermaid/src/diagrams/common/{svgDrawCommon.js => svgDrawCommon.ts} (92%) diff --git a/packages/mermaid/src/diagrams/common/common.spec.js b/packages/mermaid/src/diagrams/common/common.spec.ts similarity index 76% rename from packages/mermaid/src/diagrams/common/common.spec.js rename to packages/mermaid/src/diagrams/common/common.spec.ts index d1c68e892..cfef5d58d 100644 --- a/packages/mermaid/src/diagrams/common/common.spec.js +++ b/packages/mermaid/src/diagrams/common/common.spec.ts @@ -1,15 +1,15 @@ import { sanitizeText, removeScript, parseGenericTypes } from './common.js'; -describe('when securityLevel is antiscript, all script must be removed', function () { +describe('when securityLevel is antiscript, all script must be removed', () => { /** - * @param {string} original The original text - * @param {string} result The expected sanitized text + * @param original - The original text + * @param result - The expected sanitized text */ - function compareRemoveScript(original, result) { + function compareRemoveScript(original: string, result: string) { expect(removeScript(original).trim()).toEqual(result); } - it('should remove all script block, script inline.', function () { + it('should remove all script block, script inline.', () => { const labelString = `1 Act1: Hello 11 Act2: @@ -25,7 +25,7 @@ describe('when securityLevel is antiscript, all script must be removed', functio compareRemoveScript(labelString, exactlyString); }); - it('should remove all javascript urls', function () { + it('should remove all javascript urls', () => { compareRemoveScript( `This is a clean link + clean link and me too`, @@ -34,11 +34,11 @@ describe('when securityLevel is antiscript, all script must be removed', functio ); }); - it('should detect malicious images', function () { + it('should detect malicious images', () => { compareRemoveScript(``, ``); }); - it('should detect iframes', function () { + it('should detect iframes', () => { compareRemoveScript( ` `, @@ -47,8 +47,8 @@ describe('when securityLevel is antiscript, all script must be removed', functio }); }); -describe('Sanitize text', function () { - it('should remove script tag', function () { +describe('Sanitize text', () => { + it('should remove script tag', () => { const maliciousStr = 'javajavascript:script:alert(1)'; const result = sanitizeText(maliciousStr, { securityLevel: 'strict', @@ -58,8 +58,8 @@ describe('Sanitize text', function () { }); }); -describe('generic parser', function () { - it('should parse generic types', function () { +describe('generic parser', () => { + it('should parse generic types', () => { expect(parseGenericTypes('test~T~')).toEqual('test'); expect(parseGenericTypes('test~Array~Array~string~~~')).toEqual('test>>'); expect(parseGenericTypes('test~Array~Array~string[]~~~')).toEqual( diff --git a/packages/mermaid/src/diagrams/common/svgDrawCommon.js b/packages/mermaid/src/diagrams/common/svgDrawCommon.ts similarity index 92% rename from packages/mermaid/src/diagrams/common/svgDrawCommon.js rename to packages/mermaid/src/diagrams/common/svgDrawCommon.ts index 9a4ce8aa2..7e89b7e7f 100644 --- a/packages/mermaid/src/diagrams/common/svgDrawCommon.js +++ b/packages/mermaid/src/diagrams/common/svgDrawCommon.ts @@ -1,3 +1,4 @@ +// @ts-nocheck - ignore to convert to TS import { sanitizeUrl } from '@braintree/sanitize-url'; export const drawRect = function (elem, rectData) { @@ -12,7 +13,7 @@ export const drawRect = function (elem, rectData) { rectElem.attr('ry', rectData.ry); if (rectData.attrs !== 'undefined' && rectData.attrs !== null) { - for (let attrKey in rectData.attrs) { + for (const attrKey in rectData.attrs) { rectElem.attr(attrKey, rectData.attrs[attrKey]); } } @@ -27,8 +28,8 @@ export const drawRect = function (elem, rectData) { /** * Draws a background rectangle * - * @param {any} elem Diagram (reference for bounds) - * @param {any} bounds Shape of the rectangle + * @param elem - Diagram (reference for bounds) + * @param bounds - Shape of the rectangle */ export const drawBackgroundRect = function (elem, bounds) { const rectElem = drawRect(elem, { @@ -69,7 +70,7 @@ export const drawImage = function (elem, x, y, link) { const imageElem = elem.append('image'); imageElem.attr('x', x); imageElem.attr('y', y); - var sanitizedLink = sanitizeUrl(link); + const sanitizedLink = sanitizeUrl(link); imageElem.attr('xlink:href', sanitizedLink); };