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

sprites

v0.2.3

Published

css auto sprites

Downloads

144

Readme

sprites

css auto sprites

NPM version Build Status Coverage Status Dependency Status

INSTALL

npm install sprites

intro

特性

  • sprites自动分析传入css文件列表中的background部分,根据一定规则匹配出所有的背景图将之合并,即自动雪碧图
  • 解析语法树进行识别,保证准确性
  • 区分不同的图片格式,包括png8和png24
  • 区分高清图,即1倍和2倍
  • 提供底层接口,返回合并后的图片二进制数据,存储由应用层自己控制
  • 中文编码,ES6书写,转换为ES5

使用说明

  • 构造器传入css列表
  • 调用解析方法获取拼好的二进制图像数据
  • 存储好图像后调用替换方法传入图像url
  • 获得其返回生成的css内容列表

API

Sprites

  • constructor(css列表:Array<Object>, 根路径:String = '', 间距:int = 10) 传入需要解析的css列表,可选根路径和图片拼接间距
[{
  "路径": String,
  "内容": String = null
}]
  • 解析():Array<Object> 解析css列表,提取background部分,返回拼好的图片列表数据
  • 仅识别background缩写,分开的background-image将忽略
  • 前缀hack(如:-background)将忽略
  • background的url值为base64、线上地址时将忽略
  • background设置了position时将忽略
  • 此选择器的width/height为0时将忽略
  • 未设置width/height或不为px时将读取图片高宽
  • 图片如果是相对根路径,必须提供根路径配置
[{
  "图像": Buffer,
  "后缀": String
}]
  • 替换(url列表:Array<String>):Array<String> 在解析的基础上,将存好的图片的url数组传回,替换掉原css中的引用,索引按解析()方法中的返回顺序
  • 读根路径():String 返回根路径
  • 写根路径(根路径:String):void 设置根路径
  • 读间距():String 返回间距
  • 写间距(间距:int):void 设置间距

静态属性

  • 添加关键字(关键字:String/Array<String>):void 当底层css解析器无法识别新增的css样式关键字时,用此方法添加