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 🙏

© 2025 – Pkg Stats / Ryan Hefner

iconfont-to-vue

v0.1.1

Published

> A util to transform `iconfont.js` to `Iconfont.vue`

Readme

Iconfont to Vue

A util to transform iconfont.js to Iconfont.vue

介绍

Iconfont.cn 提供了 “Symbol 引用” 的 js 代码,但是个人不喜欢直接引入那个 iconfont.js 文件,更喜欢作为一个函数式组件 Iconfont.vue 引入到 Vue 项目中。所以简单通过字符串处理把 iconfont.js 转换为 Iconfont.vue,顺便把样式也加进去。

参考 Iconfont 帮助 - symbol 引用

使用方式

安装 iconfont-to-vue

npm install -g iconfont-to-vue

iconfont 下载至本地后,会得到这么一堆文件:

download
├── demo.css
├── demo_index.html
├── iconfont.css
├── iconfont.eot
├── iconfont.js # Symbol 引用的 js 文件
├── iconfont.svg
├── iconfont.ttf
├── iconfont.woff
└── iconfont.woff2

运行 iconfont-to-vue 进行转换:

iconfont-to-vue iconfont.js
# 或者用短一点的别名 itv
itv iconfont.js
# 自定义生成的文件名
iconfont-to-vue iconfont.js MyIconfont.vue

默认会生成 Iconfont.vue

<template functional>
<svg v-show="false">
  <symbol
    id="icon-github"
    viewBox="0 0 1024 1024"
  >
    <path d="....." />
  </symbol>
</svg>
</template>

<script>
export default {
  name: 'Iconfont',
}
</script>

<style>
.icon {
  width: 1em; height: 1em;
  vertical-align: -0.15em;
  fill: #333;
  overflow: hidden;
}
</style>

在项目最外层引入 Iconfont 组件,然后自行创建一个 Icon 组件来使用即可,例如:

<template>
  <svg
    class="icon"
    :style="{ fill: color }"
  >
    <use :xlink:href="`#icon-${name}`" />
  </svg>
</template>

<script>
export default {
  name: 'Icon',

  props: {
    name: {
      type: String,
      required: true,
    },

    color: {
      type: String,
      required: false,
      default: '#333',
    },
  },
}
</script>

当然,把 <style> 标签放在这个组件里也是可以的,这个就随意发挥了。