Skip to content

Adds isEmoji validator #2575

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ yarn.lock
/index.js
validator.js
validator.min.js

.idea
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import isLicensePlate from './lib/isLicensePlate';
import isStrongPassword from './lib/isStrongPassword';

import isVAT from './lib/isVAT';
import isEmoji from './lib/isEmoji';

const version = '13.15.15';

Expand Down Expand Up @@ -245,6 +246,7 @@ const validator = {
isLicensePlate,
isVAT,
ibanLocales,
isEmoji,
};

export default validator;
8 changes: 8 additions & 0 deletions src/lib/isEmoji.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import assertString from './util/assertString';

const emojiRegex = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/;

export default function isEmoji(str) {
assertString(str);
return emojiRegex.test(str);
}
15 changes: 15 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15652,4 +15652,19 @@ describe('Validators', () => {
],
});
});
it('should validate emojis', () => {
test({
validator: 'isEmoji',
valid: [
'🎉',
'❤️',
'🍔',
],
invalid: [
'abc',
'123',
'#000000',
],
});
});
});