node package manager


Collection of helpers for css url() manipulations.


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

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();
  • changeURLContent() can now take string as the first argument.
  • Initial release.

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