Skip to content

A 👩‍❤️‍💋‍👩tiny👨‍👩‍👦‍👦 emoji util in JavaScript🏴󠁧󠁢󠁳󠁣󠁴󠁿

License

Notifications You must be signed in to change notification settings

zhangzhiqiang37/emoji-utils

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

emoutils

A tiny emoji util in JavaScript to solve all these things:

javascript-emoji-issues

Installation

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>

API

  • isEmoji(str = ''): Whether str is emoji or not
  • containsEmoji(str = ''): Whether str contains emoji or not
  • str2unicodeArray(str = ''): Convert str to an array
  • length(str = ''): Return the length of str
  • substr(str = '', start = 0, len = Infinity): Return a sub-string of str
  • matchOneEmoji(str = '', fromStrStart = true): Match one leading emoji by default, return '' if failed
  • toArray(str = ''): Convert str to single char/emoji array (like str.split('') with emoji supports)

Changelog

2.0.0

  • (BREAKING) Basic emojis before 0xFFFF supports (PR#5 for details, and #79efbd7 for breaking case)
  • matchOneEmoji(): A new parameter fromStrStart supports
  • substr(): A negative value for the start parameter bug fixes
  • Performance optimization

1.0.0

  • (BREAKING) Unicode Emoji Spec oriented enhancements (PR#1 for details, and #8c2def7 for breaking case)
  • matchOneEmoji() exported

0.0.1

References

About

A 👩‍❤️‍💋‍👩tiny👨‍👩‍👦‍👦 emoji util in JavaScript🏴󠁧󠁢󠁳󠁣󠁴󠁿

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%