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

images-to-variables

v0.4.1

Published

A simple utility for generating Sass/Less variables for images.

Downloads

58

Readme

images-to-variables

NPM version Build status Coverage Status Dependency Status

A simple utility for generating Sass/Less variables for images.

Installation

Install from NPM:

npm install images-to-variables

Using from Node

To generate encoded image values from Node, call the create function. A promise is returned and an array containing the encoded variables is passed to handlers:

var imagesToVariables = require('images-to-variables');

imagesToVariables.create( '*.png' ).then( function( variables ) {
	console.log( variables[0].name );
	console.log( variables[0].length );
	console.log( variables[0].value );
} );

A Note About Encoding: currently, the .png contents are base-64 encoded so it can be safely included. For .svg, the contents are simply escaped as per RFC 2397.

Options

Output File

Specify the dest option to write the variables directly to a file :

imagesToVariables.create( '*.png', { dest: variables.less } );

Prefix Variables

Specify the prefix option to prefix the generated variables:

imagesToVariables.create( '*.png', { prefix: 'vui-' } );

Sass

Specify the scssFormatter if you want scss variables:

imagesToVariables.create(
	'*.png', {
		formatter: imagesToVariables.scssFormatter
	}
);

Less

The default variable format is Less, however you can explicitly specify the lessFormatter if desired:

imagesToVariables.create(
	'*.png', {
		formatter: imagesToVariables.lessFormatter
	}
);

Compression

By default, images are minified using imagemin before encoding the variables. This can optionally be disabled by providing the optimize option:

imagesToVariables.create( '*.png', { optimize: false } );

Using from CLI

Creating variables from the CLI is a piece of cake. For example, the following commands will generate Less and Scss files containing variables formatted for Less or Scss respectively. A variable is generated for each file represented by the *.png pattern, and the variables will be prefixed with vui-.

imgtoless -p vui- -o variables.less *.png

imgtoscss -p vui- -o variables.scss *.png

Note: Currently, the images must be uniquely named. The module currently does not handle duplicate file names spread across directories, but this could be added.

Versioning and Releasing

This repo is configured to use semantic-release. Commits prefixed with fix: and feat: will trigger patch and minor releases when merged to main.

To learn how to create major releases and release from maintenance branches, refer to the semantic-release GitHub Action documentation.