npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wechat-emojify

v1.0.0

Published

[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

Downloads

5

Readme

wechat-emojify

styled with prettier

在网页上正确显示微信昵称中的 emoji

Background

微信有一套自己的 emoji 编码,即类似 '\uexxx', x=[0-9a-f] 的格式。在请求微信获取用户信息时,用户昵称中的 emoji 会以微信的 emoji 编码方式返回,虽然该编码在微信中能够正常解析,但在浏览器中会往往被渲染成小方块 。这时需要我们对用户昵称进行一些特殊处理,才能使其正常显示。

Install

yarn add wechat-emojify

Usage

import { wechatEmojify, wechatEmojiMap } from 'wechat-emojify'
// or:
// import wechatEmojify from 'wechat-emojify'

// single emoji
wechatEmojify('\ue404') // 😁
// emoji in a string
wechatEmojify('I love you \ue327') // I love you 💓
// mixed wechat-emoji and utf-8-emoji
wechatEmojify('\ue32c I love you \ud83d\udc93') // 💛 I love you 💓

// use emoji map directly
wechatEmojiMap['\ue404'] // 😁

自己生成 emoji 对照表

/* 请在浏览器控制台中粘贴以下代码 */
var emoji = ''
var noop = function() {}
var copy = copy || noop
var genCode = (start, end) =>
    [...Array(end - start + 1)].map((_, i) =>
        eval("'\\ue" + ('00' + (i + start + 1).toString(16)).slice(-3) + "'")
    )
// 每组字符范围的终点位置不确定,可自行调整
var code = [
    ...[
        [0x000, 0x059],
        [0x100, 0x159],
        [0x200, 0x252],
        [0x300, 0x34c],
        [0x400, 0x44b],
        [0x500, 0x536]
    ].map(([start, end]) => genCode(start, end))
].reduce((a, b) => a.concat(b))
if (emoji) {
    var emojiList = emoji.split(',')
    var emojiMap = code.reduce((map, char, idx) => {
        map[char] = emojiList[idx]
        return map
    }, {})
    var result = JSON.stringify(emojiMap, null, 2)
    console.log(result, copy === noop ? '' : '\n\nemoji 对照表已复制到剪贴板')
    copy(result)
} else {
    var joined = code.join(',')
    copy(joined)
    console.log(
        [
            `请在微信客户端粘贴以下代码, 并将生成的emoji文本复制到上方的emoji变量处;`,
            `然后重新运行脚本,即可自动复制 emoji 对照表至剪贴板。`,
            `\n${joined}\n`,
            copy === noop ? '' : `(已复制,请到微信中粘贴)`
        ].join('\n')
    )
}