Giter Club home page Giter Club logo

css-declaration-sorter's Introduction

CSS declaration sorter logo

CSS Declaration Sorter

Travis Build Status npm version David Dependencies Status David devDependencies Status

A Node.js module and PostCSS plugin to sort CSS declarations based on their property names. Ensuring the CSS is organized, more consistent and in order... Besides, sorted CSS is smaller when gzipped because there will be more similar strings. The intention of this module is to sort the source CSS code of a project in the build process. Check out the Atom package for individual usage.

Alphabetical example

Input:

body {
    display: block;
    animation: none;
    color: #C55;
    border: 0;
}

Output:

body {
    animation: none;
    border: 0;
    color: #C55;
    display: block;
}

Niceness

  • Up-to-date CSS properties fetched from the MDN Web Platform.
  • Sort using your own defined order.
  • Nested rules sorting support.
  • Less and SCSS support when combined with either postcss-scss or postcss-less.
  • Thought-out sorting orders out of the box, approved by their authors.

Sorting orders

  • Alphabetically
    alphabetically
    Default, ordering in a simple alphabetical manner from a - z.

  • SMACSS
    smacss
    Ordering from most important, flow affecting properties, to least important properties.

    • Box
    • Border
    • Background
    • Text
    • Other
  • Concentric CSS
    concentric-css
    Starts outside the box model, moves inward.

    • Positioning
    • Visibility
    • Box model
    • Dimensions
    • Text
  • Custom order
    Provide your own order by passing the location of a JSON file containing an array.

Usage

npm install css-declaration-sorter --save-dev

CLI

This module does not include its own CLI but works with the official PostCSS CLI. To use the examples below, install postcss-cli or prefix with npx.

Piping out result from file:
postcss input.css --use css-declaration-sorter | cat

Sorting multiple files by overwriting:
postcss *.css --use css-declaration-sorter --replace --no-map

Vanilla JS

const fs = require('fs');
const postcss = require('postcss');
const cssDeclarationSorter = require('css-declaration-sorter');

postcss([cssDeclarationSorter({order: 'smacss'})])
  .process(fs.readFileSync('some.css'))
  .then(function (result) {
    fs.writeFileSync('some.css', result.css);
  });

Gulp

const gulp = require('gulp');
const gulpPostcss = require('gulp-postcss');
const cssDeclarationSorter = require('css-declaration-sorter');

gulp.task('css', function () {
  return gulp.src('some.css')
    .pipe(gulpPostcss([cssDeclarationSorter({order: 'smacss'})]))
    .pipe(gulp.dest('./'));
});

See PostCSS documentation for more examples and other environments.

css-declaration-sorter's People

Contributors

aleclarson avatar ben-eb avatar greenkeeper[bot] avatar greenkeeperio-bot avatar lexich avatar siilwyn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.