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

replace-css-url

v1.2.6

Published

Replace all url paths and @import paths within css text, with custom function map.

Downloads

2,999

Readme

replace-css-url

Independent lib to replace all url() and @import paths within css text, with custom function map.

This lib will try to keep the original css style format(quote with single, double, or none), or even worked when there's syntax error.

CircleCI

Install

As CLI:

npm install -g replace-css-url

As javascript module:

npm install replace-css-url

Usage

As CLI:

  Usage
  $ replace-css-url [globs] options...
  Options
  --version           Show version info
  --help              Show help info
  --exec, -e          [REQUIRED] Execute function to replace for every css file with "(url, fileName)=>newCSS"
  --ignore, -i        Ignore blobs for file paths
  --backup, -b        Create backup for each replace

  globs default to '**/*.css'

  Examples
  $ replace-css-url './assets/**/*.css' './static/**/*.css' --exec '(url, file)=>url'

As javascript module:

const replace_css_url = require('replace-css-url')

const css = `
@import "a.css"
@import url( b.css )
p { background: url('c.png') }
`

// prefix each path with 'http://myhost/'
console.log( replace_css_url(
  css,
  function(path){
    return 'http://myhost/' + path
  }
) )

// result css
`@import "http://myhost/a.css"
@import url( http://myhost/b.css )
p { background: url('http://myhost/c.png') }
`

This lib should be used in node, as a preprocessor of css.

If you want dynamicaly change url in browser, check this lib: cssobj

API

lib(css, mapFunc)

  • css [string]

The css string want to be altered.

  • mapFunc [function], signature: function(path){return newPath}

A function that accept path for each appearance, both in @import or inside url( ).

Return the new path that wanted.

  • RETURN [string]

The altered css with new paths.

If the return_value start with ' or ", then you can replace/add the quote instead of original one, see #1

Gotcha

This lib don't match any empty url( ) or '' ""

LICENSE

MIT