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

sourcemap-updater

v0.1.1

Published

modify css and update source map

Downloads

12

Readme

sourcemap-updater

Build Status

A tool help to modify css and update sourcemap automatically.

Assume that you have a css (maybe generated via sass/postcss) and a corresponding sourcemap. If you want to modify the css (such as delete one declaration, change a prop value), you could modify directly, but the sourcemap would be inaccurate.

This lib will help you modify css (more convenient/powerful), and update sourcemap automatically. This means you no longer need to care about sourcemap when you modify css.

Installation and Usage

npm i --save sourcemap-updater

And then

const update = require('sourcemap-updater')

const res = update([
    readFileSync(`${__dirname}/res/concated.css`),
    readFileSync(`${__dirname}/res/concated.css.map`)
], {
    updater (str, node, type) {
        // for `prop-value`s, remove all newline of value.
        if (!type && node && node.prop) {
            node.value = node.value.replace(/\s*\n\s*/g, '')
            return node.toString() + ';'
        }
        return false
    }
})

writeFileSync(`${__dirname}/res/concated.css`, res.css)
writeFileSync(`${__dirname}/res/concated.css.map`, res.map)

API

update(data[, options])

  • data is Array, data[0] is css content (String/Buffer), and data[1] is original sourcemap (String/Buffer/Object).

  • options is Object. And options.updater is Function, options.file is String

    options.updater is like function(str, node, type){}, is the same as postcss/builder. You can use it to change css. For the return value of the func:

      1. If you return `false`, this part string would keep the same.
      2. If you return `String`, this `string` will be used (as the replacement).
      3. Otherwise, this part string will be deleted.

    options.file is String, the relative file path of the css content. It will be used when original sourcemap is invalid.

License

MIT