emoji 表情

js-emoji - Display emoji in the browser, everywhere

Build StatusCoverage Status

Most macOS and iOS versions allow display and input of emoji. It's nice to show them onother devices too, and the browser is a good place to do it. This library converts emoji(either from character codes or colon-sequences like :smile:) into something that willwork on the host computer - either native character codes, a CSS styled span or a textrepresentation.

Installation

Either clone the git repo, or npm install emoji-js

Usage

 
  
<link href="emoji.css" rel="stylesheet" type="text/css" />
<script src="emoji.js" type="text/javascript"></script>
<script type="text/javascript">
 
var emoji = new EmojiConvertor();
 
// replaces \u{1F604} with platform appropriate content
var output1 = emoji.replace_unified(input);
 
// replaces :smile: with platform appropriate content
var output2 = emoji.replace_colons(input);
 
// force text output mode
emoji.text_mode = true;
 
// show the short-name as a `title` attribute for css/img emoji
emoji.include_title = true;
 
// change the path to your emoji images (requires trailing slash)
// you can grab the images from the emoji-data link here:
// https://github.com/iamcal/js-emoji/tree/master/build
emoji.img_sets.apple.path = 'http://my-cdn.com/emoji-apple-64/';
emoji.img_sets.apple.sheet = 'http://my-cdn.com/emoji-apple-sheet-64.png';
 
// Configure this library to use the sheets defined in `img_sets` (see above)
emoji.use_sheet = true;
 
// find out the auto-detected mode
alert(emoji.replace_mode);
 
// add some aliases of your own - you can override builtins too
emoji.addAliases({
  'doge' : '1f415',
  'cat'  : '1f346'
});
 
// remove your custom aliases - this will reset builtins
emoji.removeAliases([
  'doge',
  'cat',
]);
 
// convert colons to unicode
emoji.init_env(); // else auto-detection will trigger when we first convert
emoji.replace_mode = 'unified';
emoji.allow_native = true;
var output3 = emoji.replace_colons(input);
 
</script> 

You can view a live demo here.

原文链接:https://www.npmjs.com/package/emoji-js

猜你喜欢

转载自blog.csdn.net/u011504963/article/details/80922237