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

immutable-css

v1.1.2

Published

A CSS linter for immutable selectors.

Downloads

352

Readme

Build Status js-standard-style

Best practices suggest avoiding overriding styles from vendor libraries to prevent unwanted side effects. Base library styles should not be altered – or as Harry Roberts describes, base styles should be treated as Immutable CSS.

See the interactive web app.

Installation

npm install --save immutable-css

Usage

immutableCss.processFiles(immutableSourceCss, customCss, options) takes two stylesheet paths, and ensures the custom CSS doesn't override any selectors contained within the immutable source. This is typically best when comparing vendor CSS (Bootstrap, Tachyons, Basscss, etc.) to your app's customizations.

var immutableCss = require('immutable-css')

immutableCss.processFiles('css/vendor.css', 'css/app.css')
// => [...]

immutableCss.processGlob(cssGlob, options) takes a glob that matches CSS files and ensures that no stylesheet overrides selectors contained within another. This is useful to ensure that CSS partials aren't mixing concerns by mutating selectors contained within another file.

var immutableCss = require('immutable-css')

immutableCss.processGlob('src/css/**/*.css', { verbose: true })

Using with PostCSS

Immutable CSS detects mutations among files by leveraging PostCSS sourcemaps. It is also best used as a PostCSS plugin in tandem with postcss-import and postcss-reporter.

var fs = require('fs')
var postcss = require('postcss')
var import = require('postcss-import')
var reporter = require('postcss-reporter')
var immutableCss = require('immutable-css')

var css = fs.readFileSync('styles.css', 'utf8')

var mutations = postcss([import(), immutableCss(), reporter()])
                  .process(css, { from: 'styles.css' })

Using with Gulp

var gulp = require('gulp')
var postcss = require('gulp-postcss')
var import = require('postcss-import')
var reporter = require('postcss-reporter')
var immutableCss = require('immutable-css')

gulp.task('immutable', function () {
  var processors = [
    import,
    immutableCss,
    // If you want Immutable CSS to halt the gulp pipline if there are any warnings
    // then set throwError to true
    reporter({clearMessages: true, throwError: false})
  ]
  
  gulp.src('assets/css/base.css')
    .pipe(postcss(processors))
    .pipe(gulp.dest('dist/css'))
})

Input

@import 'basscss';

.button {}
.left {}
.something-else {}

Output

⚠  .button was mutated 2 times
[line 93, col 1]: /css/basscss.css
[line 3, col 1]: /css/custom.css
[immutable-css]
⚠  .left was mutated 2 times
[line 291, col 1]: /css/basscss.css
[line 4, col 1]: /css/custom.css
[immutable-css]

Options

  • strict (Boolean): Whether class mutations are allowed in the same file. Default: false.
  • ignoredClasses (Array): List of classes to ignore for mutation violations. Ex: ['.some-mutable-class']
  • immutableClasses (Array): List of classes to check against. Ex: ['.button', '.foobar']
  • immutablePrefixes (Array): List of prefix regexes that are immutable. Ex: [/\.u\-/, /\.util\-/]
  • callback (Function): Callback that receives a mutations object. Ex: function (mutations) { console.log(mutations) }
  • verbose (Boolean): Whether mutations are logged (defaults to true with PostCSS).

Using the callback

Immutable CSS accepts an optional callback, which returns the mutations hash. The key is the mutated class name, the value is an array of mutating filenames.

postcss([
  import(),
  immutableCss({ ignoredClasses: ['.button'] }, function(mutations) {
    console.log(mutations)
    // => { '.foobar': [] }
  })
]).process(css, { from: cssFile })

Using the immutable-css-cli

npm i -g immutable-css-cli
immutable-css css/main.css
⚠  .button was mutated 2 times
[line 93, col 1]: /css/_basscss.css
[line 11, col 1]: /css/_custom.css
[immutable-css]
⚠  .left was mutated 2 times
[line 291, col 1]: /css/_basscss.css
[line 15, col 1]: /css/_custom.css
[immutable-css]

https://github.com/johnotander/immutable-css-cli

Dependencies

Related Reading

License

MIT

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Crafted with <3 by @jxnblk & @4lpine.


This package was initially generated with yeoman and the p generator.