Skip to content

Commit c1d1be3

Browse files
dilaouidpotb
authored andcommitted
fix: change removeEmoji regex to include custom emojis (#63)
1 parent 1f054f6 commit c1d1be3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/__tests__/regex.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { isASocialNetworkUrl } from '../helpers/regex.helper';
3+
import { isASocialNetworkUrl, removeEmoji } from '../helpers/regex.helper';
44

55
describe('Helpers: Regex', () => {
66
describe('Rule: isASocialNetworkUrl should regex correctly an url', () => {
@@ -15,4 +15,11 @@ describe('Helpers: Regex', () => {
1515
expect(result).toBe(false);
1616
});
1717
});
18+
describe('Rule: removeEmoji should remove all emojis from a string', () => {
19+
it('removeEmoji() should remove all emojis from a string', () => {
20+
const text = '👋 Hello, World!<:SpongebobMock:1136008737669259407>';
21+
const result = removeEmoji(text);
22+
expect(result).toBe(' Hello, World!');
23+
});
24+
});
1825
});

src/helpers/regex.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const socialNetworksUrlRegex = new RegExp(
22
'^(https?://)?(www.)?(facebook.com|fb.me|twitter.com|vxtwitter.com|instagram.com|linkedin.com|youtube.com|youtu.be|pinterest.com|snapchat.com|tiktok.com)/[a-zA-Z0-9.-/?=&#_]+$',
33
);
44
const punctuationRegex = /[.,!?]/g;
5-
const emojiRegex = /(\p{Extended_Pictographic}|\p{Emoji_Component})/gu;
5+
const emojiRegex = /<a?:.+?:\d{10,30}>|\p{Extended_Pictographic}/gu;
66

77
export const isASocialNetworkUrl = (url: string): boolean => {
88
return socialNetworksUrlRegex.test(url);

0 commit comments

Comments
 (0)