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

sprity-js

v1.1.1

Published

js style processor for sprity

Readme

sprity-js

Build Status Dependency Status devDependency Status

A JS style processor for sprity

Advantages over traditional css class based sprites

Check out React: css in js for a good talk on the basic advantages.

Here's a couple advantages. You'll see the details in the code examples below.

Requirements

Install

npm install sprity sprity-js --save-dev

Usage

Here's a example using gulp, but see sprity for full documentation.

var gulp = require('gulp')
var sprity = require('sprity');
var sprityJS = require('sprity-js');

gulp.task('sprites', function () {
  return sprity.src({
    src: './images/**/*.png',
    style: 'Sprite.js',
    dimension: [{
      ratio: 1, dpi: 72
    }, {
      ratio: 2, dpi: 144
    }],
    split: true,
    processor: sprityJS // The important part for sprity JS
  })
  .pipe(gulp.dest('sprites/'));
});

Output

Here's an example of what the output might look like. This example assumes you're using split: true in your sprity config.

images
|- testFolder1
    |- test1.png
module.exports = {
    "TestFolder1": {
        "Test1": {
            "backgroundPosition": "-0px -0px",
            "width": "40px",
            "height": "40px",
            "backgroundImage": "url('../images/sprite-testFolder1.png')",
            "backgroundSize": "20px 20px",
            "@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 144dpi)": {
                "backgroundImage": "url('../images/[email protected]')",
                "backgroundSize": "40px 40px"
            }
        }
    }
}

How to use it in your code

Imagine we had two images in our app folder. rocketship.png and rocketship_hover.png. In our js these would be represented by Sprites.App.Rocketship and Sprites.App.RocketshipHover. Here's an example using React and Radium of what it might look like.

var Radium = require('radium');
var React = require('react');

@Radium
class Icon extends React.Component {
    static propTypes = {
        sprite: React.PropTypes.object.isRequired,
        hoverSprite: React.PropTypes.object,
    };

    render() {
        return (
            <span
                style={[
                    this.props.sprite,  // Radium automatically handles the @media rules in your sprite object
                    {':hover': this.props.hoverSprite},
                ]}
            />
        );
    }
}

// Where we want to use the component
var Sprites = require('Sprites.js'); // Wherever you put your sprity output.

<Icon sprite={Sprites.App.Rocketship} hoverSprite={Sprites.App.RocketshipHover} />

Overwriting styles

One of the issues I ran into using sprity with css outputs was with not being able to control the order of the output. This became an annoyance with try to overwriting styles. With javascript that issue is gone completely. In this example the :hover state will always take precedence over the styles of base sprite.

style={[
    this.props.sprite,
    {':hover': this.props.hoverSprite}
]}

Programmatic checking

We could also easily write a component that automatically renders the hover state if one exists. Something like this would work great.

var Radium = require('radium');
var React = require('react');
var Sprites = require('Sprites.js');  // Wherever you put your sprity output.

@Radium
class Icon extends React.Component {
    static propTypes = {
        sprite: React.PropTypes.object.isRequired,
    };

    render() {
        return (
            <span
                style={[
                    // You may want to pass `App` as a prop as well.
                    Sprties.App[this.props.sprite],
                    // If the sprite does not have a hover state this will be undefined and still work great.
                    {':hover': Sprties.App[this.props.sprite + 'Hover']},
                ]}
            />
        );
    }
}

// Where we want to use the component

<Icon sprite="Rocketship" />

Easy Linting

Now that all our sprite are in a js file its easy to itterator over them and lint them. Check out this gist for making sure hover and active images have the same dimensions as their root image


Gitter