From baf1d8e5e60240303fae6189fd447e6ea09ecdce Mon Sep 17 00:00:00 2001 From: louis Date: Fri, 20 Oct 2023 22:13:31 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20replaceMagic=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/message/Message.tsx | 3 +-- src/lib/replaceLinksHelper.test.ts | 33 ------------------------------ src/lib/replaceLinksHelper.ts | 12 ----------- 3 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 src/lib/replaceLinksHelper.test.ts delete mode 100644 src/lib/replaceLinksHelper.ts diff --git a/src/components/message/Message.tsx b/src/components/message/Message.tsx index 79cf8c8d..38ab79c0 100644 --- a/src/components/message/Message.tsx +++ b/src/components/message/Message.tsx @@ -1,6 +1,5 @@ import React, { FC, useState } from 'react' import { Message as MessageType } from '../../api/Message' -import { replaceMagic } from '../../lib/replaceLinksHelper' import MessageModalDelete from './MessageModalDelete' import MessageMap from './MessageMap' import { Ticker } from '../../api/Ticker' @@ -32,7 +31,7 @@ const Message: FC = ({ message, ticker }) => { setDeleteModalOpen(false)} open={deleteModalOpen} />

'), }} style={{ paddingRight: theme.spacing(6) }} /> diff --git a/src/lib/replaceLinksHelper.test.ts b/src/lib/replaceLinksHelper.test.ts deleted file mode 100644 index 4ab52375..00000000 --- a/src/lib/replaceLinksHelper.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { replaceMagic } from './replaceLinksHelper' - -describe('helper', function () { - test('replace links', function () { - const text = 'https://www.systemli.org' - - expect(replaceMagic(text)).toBe('www.systemli.org') - }) - - test('replace twitter hashtag', function () { - const text = '#hashtag' - - expect(replaceMagic(text)).toBe('#hashtag') - }) - - test('replace twitter user handle', function () { - const text = '/cc @systemli' - - expect(replaceMagic(text)).toBe('/cc @systemli') - }) - - test('replace email address', function () { - const text = 'sent mail to admin@systemli.org' - - expect(replaceMagic(text)).toBe('sent mail to admin@systemli.org') - }) - - test('replace newline with
tag', function () { - const text = 'newline\nnewtext\r\n' - - expect(replaceMagic(text)).toBe('newline
newtext
') - }) -}) diff --git a/src/lib/replaceLinksHelper.ts b/src/lib/replaceLinksHelper.ts deleted file mode 100644 index 6af9d4b3..00000000 --- a/src/lib/replaceLinksHelper.ts +++ /dev/null @@ -1,12 +0,0 @@ -// FIXME: Might be better to use a library like validator.js -// to catch more cases. -export const replaceMagic = (text: string): string => { - return text - ? text - .replace(/(https?:\/\/([a-zA-Z0-9._\-/]+))/g, '$2') - .replace(/#(\S+)/g, '#$1') - .replace(/ @(\S+)/g, ' @$1') - .replace(/([a-zA-Z0-9_\-.]+@[a-zA-Z0-9_-]+.[a-zA-Z]+)/g, '$1') - .replace(/(?:\r\n|\r|\n)/g, '
') - : '' -}