Skip to content

fix: change removeEmoji regex to include custom emojis #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/__tests__/regex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { isASocialNetworkUrl } from '../helpers/regex.helper';
import { isASocialNetworkUrl, removeEmoji } from '../helpers/regex.helper';

describe('Helpers: Regex', () => {
describe('Rule: isASocialNetworkUrl should regex correctly an url', () => {
Expand All @@ -15,4 +15,11 @@ describe('Helpers: Regex', () => {
expect(result).toBe(false);
});
});
describe('Rule: removeEmoji should remove all emojis from a string', () => {
it('removeEmoji() should remove all emojis from a string', () => {
const text = '👋 Hello, World!<:SpongebobMock:1136008737669259407>';
const result = removeEmoji(text);
expect(result).toBe(' Hello, World!');
});
});
});
2 changes: 1 addition & 1 deletion src/helpers/regex.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const socialNetworksUrlRegex = new RegExp(
'^(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.-/?=&#_]+$',
);
const punctuationRegex = /[.,!?]/g;
const emojiRegex = /(\p{Extended_Pictographic}|\p{Emoji_Component})/gu;
const emojiRegex = /<a?:.+?:\d{10,30}>|\p{Extended_Pictographic}/gu;

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