A tiny emoji util in JavaScript to solve all these things:
Node.js:
npm -i --save-dev emoutils
const emoutils = require('emoutils');
// or
// const { isEmoji } = require('emoutils');
const assert = require('assert');
assert.strictEqual(emoutils.isEmoji('😄'), true);
Browser:
<!-- Minified UMD version -->
<script src="https://unpkg.com/emoutils/dist/umd/emoutils.min.js"></script>
<!-- Unminified UMD version -->
<script src="https://unpkg.com/emoutils/dist/umd/emoutils.js"></script>
<!-- unminified ES version -->
<script src="https://unpkg.com/emoutils/dist/es/emoutils.js"></script>
<script>
console.log(
emojiUtils.containsEmoji('hello 👋') === true
);
</script>
isEmoji(str = '')
: Whetherstr
is emoji or notcontainsEmoji(str = '')
: Whetherstr
contains emoji or notstr2unicodeArray(str = '')
: Convertstr
to an arraylength(str = '')
: Return the length ofstr
substr(str = '', start = 0, len = Infinity)
: Return a sub-string ofstr
matchOneEmoji(str = '', fromStrStart = true)
: Match one leading emoji by default, return''
if failedtoArray(str = '')
: Convertstr
to single char/emoji array (likestr.split('')
with emoji supports)
- (BREAKING) Basic emojis before 0xFFFF supports (PR#5 for details, and #79efbd7 for breaking case)
matchOneEmoji()
: A new parameterfromStrStart
supportssubstr()
: A negative value for thestart
parameter bug fixes- Performance optimization
- (BREAKING) Unicode Emoji Spec oriented enhancements (PR#1 for details, and #8c2def7 for breaking case)
matchOneEmoji()
exported
- Initial Version (JavaScript emoji utils for details)