Socket
Socket
Sign inDemoInstall

csso

Package Overview
Dependencies
8
Maintainers
4
Versions
82
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    csso

CSSO — CSS optimizer


Version published
Maintainers
4
Install size
207 kB
Created

Package description

What is csso?

CSSO (CSS Optimizer) is a CSS minifier. It performs three kinds of optimizations: structural optimizations, reducing CSS size by merging blocks with identical properties, removing overridden properties, etc.; cleaning (removing unused @media rules, cutting out the comments, etc.); and compressing (transforming values to shorter forms, merging identical selectors, etc.). It can be used as a command-line tool or as a library.

What are csso's main functionalities?

Minification

Minifies CSS by removing whitespace, comments, and making other optimizations to reduce file size.

const csso = require('csso');
const minifiedCss = csso.minify('.test { color: #ff0000; }').css;

Structural Optimization

Optimizes CSS structure by merging blocks with identical properties and removing overridden properties.

const csso = require('csso');
const optimizedCss = csso.minify('.test { color: red; } .test { font-size: 16px; }', { restructure: true }).css;

Source Map Generation

Generates a source map that can be used to debug the minified CSS by mapping it back to the original sources.

const csso = require('csso');
const result = csso.minify('.test { color: red; }', { sourceMap: true });
const minifiedCss = result.css;
const map = result.map.toString();

Other packages similar to csso

Changelog

Source

1.4.1 (October 20, 2015)

  • allow merge for display property (#167, #244)
  • more accurate rect (clip property value) merge
  • fix typo when specifying options in cli (thanks to @Taritsyn)
  • fix safe unit values merge with keyword values (#244)
  • fix wrong descendant combinator removal (#246)
  • build browser version on prepublish (thanks to @silentroach)
  • parser: store whitespaces as single token (performance and reduce memory consumption)
  • rearrange compress tests layout

1.4 (October 16, 2015)

Bringing project back to life. Changed files structure, cleaned up and refactored most of sources.

Common

  • single code base (no more src folder)
  • build browser version with browserify (no more make, and web folder), browser version is available at dist/csso-browser.js
  • main file is lib/index.js now
  • minimal node.js version is 0.12 now
  • restrict file list to publish on npm (no more useless folders and files in package)
  • add jscs to control code style
  • automate gh-pages update
  • util functions reworked
  • translator reworked
  • test suite reworked
  • compressor refactored
  • initial parser refactoring

API

  • new method minify(src, options), options:
    • restructuring – if set to false, disable structure optimisations (true by default)
    • debug - outputs intermediate state of CSS during compression (false by default)
  • deprecate justDoIt() method (use minify instead)
  • rename treeToString() method to stringify()
  • drop printTree() method
  • AST node info
    • column and offset added
    • ln renamed to line
    • fix line counting across multiple files and input with CR LF (#147)

CLI

  • completely reworked, use clap to parse argv
  • add support for input from stdin (#128)
  • drop undocumented and obsoleted options --rule and --parser (suppose nobody use it)
  • drop -off alias for --restructure-off as incorrect (only one letter options should starts with single -)
  • new option --debug that reflecting to options.debug for minify

Parsing and optimizations

  • keep all exclamation comments (#194)
  • add /deep/ combinator support (#209)
  • attribute selector
    • allow colon in attribute name (#237)
    • support for namespaces (#233)
  • color
    • support all css/html colors
    • convert hsla to rgba and hls to rgb
    • convert rgba with 1 as alpha value to rgb (#122)
    • interpolate rgb and rgba percentage values to absolute values
    • replace percentage values in rgba for normalized/interpolated values
    • lowercase hex colors and color names (#169)
    • fix color minification when hex value replaced for color name (#176)
    • fit rgb values to 0..255 range (#181)
  • calc
    • remove spaces for multiple operator in calc
    • don't remove units inside calc (#222)
    • fix wrong white space removal around + and - (#228)
  • don't remove units in flex property as it could change value meaning (#200)
  • don't merge \9 hack values (#231)
  • merge property values only if they have the same functions (#150, #227)
  • don't merge property values with some sort of units (#140, #161)
  • fix !important issue for top-right-bottom-left properties (#189)
  • fix top-right-bottom-left properties merge (#139, #175)
  • support for unicode-range (#148)
  • don't crash on ruleset with no selector (#135)
  • tolerant to class names that starts with digit (#99, #105)
  • fix background compressing (#170)

Readme

Source

NPM version Build Status Dependency Status devDependency Status

CSSO (CSS Optimizer) is a CSS minimizer unlike others. In addition to usual minification techniques it can perform structural optimization of CSS files, resulting in smaller file size compared to other minifiers.

Install

npm install -g csso

Usage

Command line

csso [input] [output] [options]

Options:

      --debug              Output intermediate state of CSS during compression
  -h, --help               Output usage information
  -i, --input <filename>   Input file
  -o, --output <filename>  Output file (result outputs to stdout if not set)
      --restructure-off    Turns structure minimization off
  -v, --version            Output the version

Some examples:

> csso in.css out.css

> csso in.css
...output result in stdout...

> echo ".test { color: #ff0000; }" | csso
.test{color:red}

> cat source1.css source2.css | csso | gzip -9 -c > production.css.gz

API

var csso = require('csso');

var compressed = csso.minify('.test { color: #ff0000; }');
console.log(compressed);
// .test{color:red}

// you may do it step by step
var ast = csso.parse('.test { color: #ff0000; }');
ast = csso.compress(ast);
var compressed = csso.translate(ast, true);
console.log(compressed);
// .test{color:red}

Documentation

May be outdated

FAQs

Last updated on 20 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc