2 Star 6 Fork 1

明天以后/wechat-emoji-parser

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

wechat-emoji-parser

微信表情解析工具,可以实现表情解析和表情发送功能

  • 可用于公众号接收用户表情消息,将表情码转换为对应的表情 html 内容
  • 还可以获取聊天表情,可以应用于聊天应用的表情

install(安装)

npm:

npm install wechat-emoji-parser -S

yarn:

yarn add wechat-emoji-parser

How to use(使用)

getEmojis(option):获取表情

import { getEmojis } from 'wechat-emoji-parser'
let emojis = getEmojis({ size: 24 })
/*emojis
[
  {
    cn: "[右哼哼]"
    code: "/:@>"
    style:{
            background: "url(https://res.wx.qq.com/wxdoc/dist/assets/img/emoji-sprite.b5bd1fe0.png) no-repeat"
            background-position: "0px 0px"
            background-size: "599.7px"
            display: "inline-block"
            height: "50px"
            width: "50px"
	}
....
]
*/
  1. 输入:option: {size: number, emojiSpriteUrl: string}

    属性名 类型 默认值 说明
    size number 64 emoji 大小,单位 px
    emojiSpriteUrl string https://res.wx.qq.com/wxdoc/dist/assets/img/emoji-sprite.b5bd1fe0.png 雪碧图文件路径,为了避免链接失效,最好将 src/assets/emoji-sprite.png 中的文件上传自己的 cdn,然后设置为对应的资源路径
  2. 输出 emojis: [ { code: string, cn: string, style: { ​ display: string ​ background: string ​ width: string ​ height: string ​ 'background-position': string ​ 'background-size': string }

}]

属性名 类型 默认值 说明
code string emoji 对应的编码,如:/:@>
cn string 中文显示,如:[右哼哼]
style Object

parseEmoji(str) 解析表情

import { parseEmoji, configParseEmoji } from 'wechat-emoji-parser'
configParseEmoji({ size: 30 }) // 设置一些参数
const res = parseEmoji('哈哈[西瓜]') // 解析文本
  • configParseEmoji(option: object) 配置解析规则

    属性名 类型 默认值 说明
    size number 64 emoji 大小,单位 px
    emojiSpriteUrl string https://res.wx.qq.com/wxdoc/dist/assets/img/emoji-sprite.b5bd1fe0.png 雪碧图文件路径,为了避免链接失效,最好将 src/assets/emoji-sprite.png 中的文件上传自己的 cdn,然后设置为对应的资源路径
    tag string 'a' 解析后的 html 标签
  • parseEmoji(str: string)

    输入:待解析的文本

    输出:解析后的内容

example

MIT License Copyright (c) 2020 明天以后 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

微信表情转换,可用于公众号接收用户表情消息,将表情转换为相应的图片 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mingtianyihou/wechat-emoji-parser.git
git@gitee.com:mingtianyihou/wechat-emoji-parser.git
mingtianyihou
wechat-emoji-parser
wechat-emoji-parser
master

搜索帮助

371d5123 14472233 46e8bd33 14472233