Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (52 sloc) 1.85 KB

css-url-edit Build Status

Collection of helpers for css url manipulations. Strongly inspired and partially based on code from cssrb project.

Getting Started

Install the module with: npm install css-url-edit

var css_url_edit = require('css-url-edit');


First of all you need to create an URLs collection from your css file.

var URLS = css_url_edit( string_with_css );

After that you will have following methids in your code:


URLS.getURLs( [mask] );

mask {regex} is an optional parameter. It will return not all found URLs, but only URLs that match this RegExp.

Returns array of unique URLs in css document.


URLS.changeCSSRoot( from_path, to_path );

from_path and to_path must be {string} with absolute path to folders.

Changes relative path of every relative url() address in the URLS object to the new base.


URLS.changeURLContent( from_value, [to_value] );

from_value {regexp|string} Mask to select urls with.
to_value {string} Rule to apply on found items.

Replace content of every URL matching RegExp with new content.



Return compiled css.


var css_url_edit = require('css-url-edit');

var URLS = css_url_edit( string_with_css );

URLS.changeURLContent( /^\/media\//, '/images/' );

var new_css = URLS.rebuildCSS();

Release History

0.2.0 What's new

  • changeURLContent() can now take string as the first argument.

0.1.0 What's new

  • Initial release.


Copyright (c) 2013 Alexey Ivanov
Licensed under the MIT license.