Skip to content

Flattens a nested (S)CSS string, "&" placeholders are supported too.

License

Notifications You must be signed in to change notification settings

fabiospampinato/css-flatten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSS Flatten

Flattens a nested (S)CSS string, & placeholders are supported too.

This is implemented using css-simple-parser, which makes it tiny and blazing fast, but there are some limitations to be aware of, read the parser's readme to learn about them.

Install

npm install css-flatten

Usage

import flatten from 'css-flatten';

// Let's make some CSS to flatten

const css = `
.foo {
  color: red;
  &:hover {
    color: green;
  }
  .bar {
    color: blue;
  }
}
`;

// Let's flatten that CSS

flatten ( css );
// .foo {
//   color: red;
// }
// .foo:hover {
//   color: green;
// }
// .foo .bar {
//   color: blue;
// }

License

MIT © Fabio Spampinato