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

@yugu/svg-color-replacer

v0.0.8

Published

一个用于替换SVG颜色的工具包

Downloads

16

Readme

项目包介绍:

  • 该项目包具备一项实用功能,即能够基于指定的主题色对 SVG 图的颜色进行动态变换。如此一来,SVG 图在不同主题场景下,就能相应呈现出契合该主题的色彩风格,这对于提升项目整体的视觉适应性以及灵活性有着显著作用。

参数:

| 参数 | 类型 | 必填 | 描述 | | :----: | :----: | :----: | :---- | | svgString | string | 是 | 代表需进行颜色更改的 SVG 图的字符串数据,是整个颜色替换操作的基础素材。 | | defaultReplaceColor | string | 是 | 确定要将 SVG 图中原有的颜色替换成的目标颜色 | | ignoreAttrs | Array | 否 | 可传入一个数组,其中的元素为在颜色替换时要被忽略的 SVG 图属性名称,以此精准控制特定属性颜色不被修改。 | | ignoreElements | array | 否 | 数组类型,用于指定在颜色替换过程中需跳过颜色更改的 SVG 图节点,确保某些节点颜色维持原状。 | | ignoreColors | array | 否 | 当存在特定颜色值无需替换时,将这些颜色值组成数组传入,从而实现对特定颜色的保留。 | | replaceColorMap | object | 否 | 接收一个对象,通过对象的键值对设定特定颜色到目标颜色的映射关系,实现个性化颜色替换策略。 |

安装

$ npm i @yugu/svg-color-replacer

# or

$ yarn add @yugu/svg-color-replacer

使用

  1. 以下是在 Vue 项目中使用该项目包的示例代码
<template>
  <div>
    <img class="svg" src="" alt="" />
  </div>
</template>
<script setup>
import svgColorReplacer from '@yugu/svg-color-replacer'
import { onMounted } from 'vue'

onMounted(() => {
  fetch('/logo.svg')
    .then(res => res.text())
    .then(data => {
      const newSvgString = svgColorReplacer({
        svgString: data,
        defaultReplaceColor: '#00f',
      })
      const blob = new Blob([newSvgString], { type: 'image/svg+xml' })
      const url = URL.createObjectURL(blob)
      const svgImg = document.querySelector('.svg')
      svgImg.src = url
    })
})
</script>