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

postcss-helpers

v0.3.3

Published

Some general purpose helpers for PostCSS, created to make working with url() and @import values more easy.

Downloads

112,134

Readme

postcss-helpers Build Status

Some general purpose helpers for PostCSS, created to make working with url() and @import values more easy. Can be used without PostCSS.

Getting Started

npm install postcss-helpers

Helpers

#createUrlsHelper( rule )

Returns new UrlsHelper object from the rule string with one or more url() (see description below).

#createImportHelper( rule )

Returns new ImportHelper object from the @import value string (see description below).

new UrlsHelper( rule )

Object for manipulating values of rules with one or multiple url().

#getOriginalRule

Returns original rule that it was created with.

#getOriginalURIS

Returns Array of all original URI in string. NOT mutated URIs.

#URIS

Array of one or more urijs objects that can be used for URI manipulations. If there is no url() in the rule returns false.

For example you can use UrlsHelper.URIS[0].href() to get value for the first url() and UrlsHelper.URIS[0].href('new_uri') to set new URI value. See full documentation.

#getModifiedRule

After you finished changing values of the URIS you can get modified rule text with this command.

new ImportHelper( rule )

Object for manipulating values of @import at-rules.

#getOriginalRule

Returns original rule that it was created with.

#getOriginalURI

Returns original URI from string. NOT mutated URI.

#URI

urijs objects that can be used for URI manipulations. If there is no url() in the rule returns false.

For example you can use ImportHelper.URI.href() to get import value and ImportHelper.URI.href('new_uri') to set new URI value. See full documentation.

#getModifiedRule

After you finished changing values of the URI you can get modified rule text with this command.

#getOriginalMediaQuery

Returns media query from original string.

#setMediaQuery( query )

Replace old media query or creates new one.

#getMediaQuery

Returns current media query from string.

Other

#regexp

Collection of some useful RegExps based on CSS specification grammar rules: http://www.w3.org/TR/CSS21/grammar.html

  • STRINGS – RegExp for css <string> with 'ig' flags.
  • URLS – RegExp for css <uri> with 'ig' flags.

Examples

Modify string with multiple url() fragments:

var helpers = require( 'postcss-helpers' );

var rule = 'url(logo1.png)', url( 'logo2.png' ), url( "logo3.png");

var helper = helpers.createUrlsHelper( rule );

helper.URIS.forEach( function( uri ) {
    uri.suffix( 'jpeg' );
} );

var modifiedRule = helper.getModifiedRule(); // url(logo1.jpeg)', url( 'logo2.jpeg' ), url( "logo3.jpeg")

Modify @import value:

var helpers = require( 'postcss-helpers' );

var rule = '"src/print.css" print';

var helper = helpers.createImportHelper( rule );

helper.URI.directory( 'dist' );
helper.getMediaQuery(); // print
helper.setMediaQuery( 'screen' );

var modifiedRule = helper.getModifiedRule(); // "dist/print.css" screen

Test if string contains url() fragments:

var helpers = require( 'postcss-helpers' );

var rule = 'url(logo1.png)', url( 'logo2.png' ), url( "logo3.png");

helpers.regexp.URIS.test( rule ); // true

Known problems

UrlsHelper() and ImportHelper() will not escape quotes in the new URI values so escape them yourself.

Release History

See CHANGELOG for detailed changes.

  • 2014-08-08   0.1.0   Initial release.
  • 2014-08-11   0.1.1   Make RegExps public. Fixed ?#iefix bug.
  • 2014-08-12   0.2.0   Added methods for getting original url() values and for media query manipulations.