emoutils

2.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i emoutils

Weekly Downloads

60

Version

2.0.0

License

MIT

Unpacked Size

85.8 kB

Total Files

13

Last publish

Collaborators

  • ayqy