# wechat-emoji-parser

> 微信表情

Latest version **2.3.1** (published 2024-11-20) · 0 weekly downloads

## Install

```sh
npm install wechat-emoji-parser
pnpm add wechat-emoji-parser
yarn add wechat-emoji-parser
bun add wechat-emoji-parser
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2024-11-20 |
| First published | 2020-01-15 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51 |
| Author | mingtianyihou33 |
| Maintainers | mingtianyihou |
| Keywords | 微信, wechat, 表情, emoji, 表情解析, 微信表情 |

## Links

- npm: https://www.npmjs.com/package/wechat-emoji-parser
- Repository: https://github.com/mingtianyihou33/wechat-emoji-parser
- Homepage: https://github.com/mingtianyihou33/wechat-emoji-parser#readme
- Issues: https://github.com/mingtianyihou33/wechat-emoji-parser/issues
- npm.io page: https://npm.io/package/wechat-emoji-parser

## Recent versions

- 2.3.1 (latest) — 2024-11-20
- 2.3.0 — 2024-09-14
- 2.2.1 — 2024-08-26
- 2.0.1 — 2021-03-29
- 2.0.0 — 2021-03-19
- 1.1.1 — 2020-07-01
- 1.1.0 — 2020-06-24
- 1.0.4 — 2020-01-19
- 1.0.3 — 2020-01-15
- 1.0.2 — 2020-01-15
- 1.0.1 — 2020-01-15
- 1.0.0 — 2020-01-15

## README

# wechat-emoji-parser

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

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

## install（安装）

npm:

```bash
npm install wechat-emoji-parser
```

pnpm:

```bash
pnpm add wechat-emoji-parser
```

## How to use（使用）

#### getEmojis(option)：获取表情

```js
import { getEmojis } from 'wechat-emoji-parser'
let emojis = getEmojis({ size: 24 })
/*emojis
[
  {
    cn: "[右哼哼]"
    code: "/:@>"
    style:{
      background: "url(...) no-repeat"
      background-size: "24px"
      display: "inline-block"
      height: "24px"
      width: "24px"
	}
....
]
*/
```

1. 输入：option: {size: number}

   | 属性名         | 类型   | 默认值                                                                | 说明                                                                                                                 |
   | -------------- | ------ | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
   | size           | number | 64                                                                    | emoji 大小，单位 px                                                                                                  |

2. 输出 emojis: 
```js
[
   {
   code: string,
   cn: string,
   style: {
     display: string,
     background: string,
     width: string,
     height: string,
     'background-size': string,
   }
}]
```

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

#### parseEmoji(str) 解析表情

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

- configParseEmoji(option: object) 配置解析规则

  | 属性名         | 类型   | 默认值                                                                | 说明                                                                                                                 |
  | -------------- | ------ | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
  | size           | number | 64                                                                    | emoji 大小，单位 px                                                                                                  |
  | tag            | string | 'a'                                                                   | 解析后的 html 标签                                                                                                   |

- parseEmoji(str: string)

  输入：待解析的文本

  输出：解析后的内容

## Example

- [vue 项目使用案例](./examples/vue-example)


## Contribution（贡献）
1. 添加表情
在src/assets/emojis里面加上表情图片
2. 添加表情配置
然后在emoji.json里面加上表情的编码规则，src字段对应表情图片的位置

---
_Source: https://npm.io/package/wechat-emoji-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
