Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svg-simple

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-simple

convert svg to be simple path without transform and simple viewBox

  • 1.0.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by1500%
Maintainers
1
Weekly downloads
 
Created
Source

svg-simple

npm version

http://iconfont.cn 底层依赖的ruby模块SimpleSvg的node版本

主要功能可以参见:http://gitlab.alibaba-inc.com/mm/iconfont-plus/issues/7

Usage

npm install svg-simple --save

var SvgSimple=require('svg-simple');

//filePath 是你需要转换处理的svg文路径,1024是处理目标高度,true表示是完美模式

//1.promise 方式
SvgSimple.parse('filePath',1024,true).then(function(parser){
	console.log(parser.toSimplePaths());
	...
})

//2.如果是KOA/CO中使用
var parser=yeild Simple.parse('filePath',1024,true);
console.log(parser.toSimplePaths());
...

//3.命令行模式,前提是全局安装`npm install svg-simple -g`

simple-svg 'filePath or filename' 1024 true

会在源文件目录生成一个 filename-simple.svg 文件

//4.也可以直接传入需要转换的svg string,即
var parser=yeild Simple.parseStr('<svg>...</svg>',1024,true);

Api

通过SvgSimple.parse方法得到的parser对象主要提了供以下方法:

parser.toSimplePaths();
parser.toSimpleSvg();
parser.toSimpleSvgFileSync();
parser.getSimpleViewPort();
parser.getSimpleViewBox();
parser.getFillColors();//返回数组,包含每条path的颜色信息
parser.getPathAttributes(); //返回 path的属性,目前支持 fill,fill-opacity,opacity

Test

npm test

如需要增加测试的svg文件,按照要求修改 ./test/test.js 文件中的 fileList数组即可

Keywords

FAQs

Package last updated on 30 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc