
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
css-declaration-sorter
Advanced tools
Sorts CSS declarations fast and automatically in a certain order.
The css-declaration-sorter npm package is a tool used to automatically sort the declarations within CSS rulesets in a consistent order. It can be integrated into build processes to ensure that CSS is organized according to a specific order, which can make the CSS easier to read and maintain. It can also potentially lead to better compression when minifying CSS files.
Sorting CSS declarations
This feature sorts the declarations within a CSS rule based on the specified order, such as 'smacss', 'concentric-css', or 'alphabetical'. The code sample shows how to use css-declaration-sorter with PostCSS to sort the declarations in a given CSS string.
const postcss = require('postcss');
const cssDeclarationSorter = require('css-declaration-sorter');
postcss([cssDeclarationSorter({ order: 'smacss' })])
.process('a { color: yellow; z-index: 2; }')
.then(result => console.log(result.css));
Integration with build tools
css-declaration-sorter can be integrated with build tools like Gulp to automatically sort CSS files during the build process. The code sample demonstrates how to set up a Gulp task that processes CSS files with css-declaration-sorter using PostCSS.
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const cssDeclarationSorter = require('css-declaration-sorter');
gulp.task('css', function () {
return gulp.src('src/*.css')
.pipe(postcss([cssDeclarationSorter({ order: 'alphabetical' })]))
.pipe(gulp.dest('dist'));
});
postcss-sorting is similar to css-declaration-sorter in that it sorts CSS properties according to a specified order. However, it also allows for sorting at-rules and rules within CSS files, providing a more comprehensive sorting capability.
stylelint-order is a plugin for stylelint that checks the order of content within declaration blocks. While it does not automatically sort the CSS, it can enforce a specific order and is often used in conjunction with stylelint to maintain code quality.
perfectionist is a PostCSS plugin that not only sorts declarations but also beautifies CSS with consistent spacing and syntax. It offers a more stylistic approach to organizing CSS compared to css-declaration-sorter, which focuses solely on sorting declarations.
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.
Input:
body {
display: block;
animation: none;
color: #C55;
border: 0;
}
Output:
body {
animation: none;
border: 0;
color: #C55;
display: block;
}
npm install css-declaration-sorter --save-dev
Usage: cssdeclsort [options] [input]
Sort CSS declarations from file(s) or stdin and output to file(s) or stdout.
Options:
-h, --help Display help text.
-v, --version Display cssdeclsort's version.
--customOrder Use provided JSON file data to order the declarations.
--directory Output to provided directory instead of current directory.
--order Use provided order instead of ordering alphabetically.
--output Output to a file instead of writing to the origin or stdout.
--verbose Log extra information about the process to the console.
Orders:
alphabetically, smacss, concentric-css
Piping data and writing to a specific file:
perfectionist input.css | cssdeclsort --output output.css
Sorting multiple files by overwriting:
cssdeclsort --order smacss *.css
const fs = require('fs');
const postcss = require('postcss');
const cssdeclsort = require('css-declaration-sorter');
postcss([cssdeclsort({order: 'smacss'})])
.process(fs.readFileSync('something.css'))
.then(function (result) {
fs.writeFileSync('something.css', result.css);
});
const gulp = require('gulp');
const gulpPostcss = require('gulp-postcss');
const cssdeclsort = require('css-declaration-sorter');
gulp.task('css', function () {
return gulp.src('something.css')
.pipe(gulpPostcss([cssdeclsort({order: 'smacss'})]))
.pipe(gulp.dest('./'));
});
See PostCSS docs for more examples and other environments.
Alphabetically
Ordering in a simple alphabetical manner from a - z.
SMACSS
Ordering from most important, flow affecting properties, to least important properties.
Concentric CSS
Starts outside the box model, moves inward.
Custom order
Provide your own order by passing an array in a JSON file.
FAQs
Sorts CSS declarations fast and automatically in a certain order.
We found that css-declaration-sorter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.