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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alicloud/iconfont-helper

v1.4.3

Published

iconfont.cn 辅助,用于注入 iconfont 或 webfont 并返回对应的 font 名,是写组件的好帮手

Readme

@alicloud/iconfont-helper

https://www.iconfont.cn 辅助,用于注入 iconfont 或 webfont 并返回对应的 font 名,是写组件的好帮手

使用 injectIconFont

定义 Icon 组件

你需要去 https://www.iconfont.cn/manage/index?manage_type=myprojects 新建或选择一个 iconfont 项目,它会有一个固定不变的 id 和跟当前内容有关的 hash,并且在它生成的 CSS 里有一份 Base64,都可以拿来,比如:

Code Example

注意以下代码比较紧凑,实际写的时候,应该拆到 types、enum、util 以减小主题文件的复杂度。

import React, {
  HTMLAttributes
} from 'react';
import styled from 'styled-components';

import {
  IconBase,
  injectIconFont
} from '@alicloud/iconfont-helper';

enum EIconType {
  alibaba = 'e68a' // 这里仅做演示,所以只写一个,注意不用写 e 前边的斜杠
}

type TIconType = keyof typeof EIconType;

interface IPropsIcon extends HTMLAttributes<HTMLSpanElement> {
  type: TIconType; // 这样可以约束传入的 type,在 TS 的帮助下不会传错
}

const PROJECT = '2373906';
const HASH = 'qpoep7hwn3';
// const BASE64 = 'data:application/x-font-woff2;charset=utf-8;base64,...';

const fontFamily = injectIconFont(PROJECT, HASH);

function getCode(props: IPropsIcon): string {
  const code = EIconType[props.type];
  
  return code ? `\\${code}` : '';
}

const ScIcon = styled(IconBase)<IPropsIcon>`
  font-family: ${fontFamily} !important;
  
  &:before {
    content: '${props => getCode(props)}';
  }
`;

export default function Icon(props: IPropsIcon): JSX.Element {
  return <ScIcon {...props} />;
}

// export 类型是好习惯
export type {
  TIconType as IconType,
  IPropsIcon as IconProps
};

使用 Icon 组件

import React from 'react';

import Icon from '...'; // 应用内部的或你把它发布成包

// 任何需要 Icon 的地方
// OK
<Icon type="alibaba" />
// TS 报错
<Icon type="ali88" />

使用 WebFont 字体

WebFont 可以让你的页面展现一些设计师希望的「美妙」字体(尤其是中文字体)。

众所周知,中文字体包不像西方字体那样,它是很大的,不可能为了视觉上的美观而让浏览器加载全量的中文字体包。

iconfont 网站提供了 webfont 的功能,你可以根据设计师给的文案去上边「定制」你要的字体。

假设,设计师要展示这样的文案:

WebFont Example

定义 WebFont 组件

你这么做:

Copy Id

import React from 'react';
import styled from 'styled-components';

import {
  injectWebFont
} from '@alicloud/iconfont-helper';

const fontFamily = injectWebFont('kygag0sd8g');

// 如果有其他的样式要求,也可以在这里加,或者在它的容器上加也行
const ScMengziKongzi = styled.span`
  font-family: ${fontFamily}, sans-serif;
`;

export default function MengziKongzi(): JSX.Element {
  return <ScMengziKongzi>孔子曰:中午不睡,下午崩溃!孟子曰:孔子说的对!</ScMengziKongzi>;
}

使用 WebFont 组件

import React from 'react';

import MengziKongzi from ':/rc/webfont/mengzi-kongzi'; // 一般在引用内部,没有意义发布成包

// 任何需要此组件的地方
<MengziKongzi />