source: frontend/node_modules/css-declaration-sorter/readme.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 4.4 KB
Line 
1<img alt='CSS declaration sorter logo' src='https://raw.githubusercontent.com/Siilwyn/css-declaration-sorter/master/logo.svg?sanitize=true' height='260' align='right'>
2
3# CSS Declaration Sorter
4[![npm][npm-badge]][npm]
5
6A Node.js module and [PostCSS] plugin to sort CSS, SCSS or Less declarations based on their property names. Ensuring styling is organized, more consistent and in order... The goal of this package is to sort the source code of a project in the build process or to decrease the distributed CSS gzipped size.
7
8Check out [the Prettier plugin](https://github.com/Siilwyn/prettier-plugin-css-order) for usage with a variety of file formats.
9
10## Niceness
11- Up-to-date CSS properties fetched from the [MDN Compatibility Data](https://github.com/mdn/browser-compat-data/) project.
12- Choose your wanted order or provide your own.
13- Nested rules sorting support.
14- SCSS and Less support when combined with either [postcss-scss](https://github.com/postcss/postcss-scss) or [postcss-less](https://github.com/webschik/postcss-less).
15- Thought-out sorting orders out of the box, **approved by their authors**.
16
17## Alphabetical example
18Input:
19```css
20body {
21 display: block;
22 animation: none;
23 color: #C55;
24 border: 0;
25}
26```
27
28Output:
29```css
30body {
31 animation: none;
32 border: 0;
33 color: #C55;
34 display: block;
35}
36```
37
38## Built-in sorting orders
39- Alphabetical
40`alphabetical`
41*Default, order in a simple alphabetical manner from a - z.*
42
43- [SMACSS](http://smacss.com/book/formatting#grouping)
44`smacss`
45*Order from most important, flow affecting properties, to least important properties.*
46 1. Box
47 2. Border
48 3. Background
49 4. Text
50 5. Other
51
52- [Concentric CSS](https://github.com/brandon-rhodes/Concentric-CSS)
53`concentric-css`
54*Order properties applying outside the box model, moving inward to intrinsic changes.*
55 1. Positioning
56 2. Visibility
57 3. Box model
58 4. Dimensions
59 5. Text
60
61## Usage
62Following the PostCSS plugin guidelines, this package depends on PostCSS as a peer dependency:
63`npm install postcss css-declaration-sorter --save-dev`
64
65### CLI
66This module does not include its own CLI but works with the official [PostCSS CLI](https://github.com/postcss/postcss-cli). To use the examples below, the `postcss-cli` package is a required dependency.
67
68Piping out result from file:
69`postcss input.css --use css-declaration-sorter | cat`
70
71Sorting multiple files by overwriting:
72`postcss *.css --use css-declaration-sorter --replace --no-map`
73
74Sorting all files in a directory with SCSS syntax using [postcss-scss](https://github.com/postcss/postcss-scss) by overwriting:
75`postcss ./src/**/*.scss --syntax postcss-scss --use css-declaration-sorter --replace --no-map`
76
77Sorting all files in the directory with SCSS syntax and SMACSS order by overwriting, using `package.json` configuration:
78```json
79"postcss": {
80 "syntax": "postcss-scss",
81 "map": false,
82 "plugins": {
83 "css-declaration-sorter": { "order": "smacss" }
84 }
85}
86```
87
88`postcss ./src/**/*.scss --replace --config package.json`
89
90### Vanilla JS
91```js
92import postcss from 'postcss';
93import { cssDeclarationSorter } from 'css-declaration-sorter';
94
95postcss([cssDeclarationSorter({ order: 'smacss' })])
96 .process('a { color: hyperblue; display: block; }', { from: undefined })
97 .then(result => console.log(
98 result.css === 'a { display: block; color: hyperblue; }'
99 ));
100```
101___
102
103**[View more usage examples](/examples) in combination with other tools.**
104
105___
106
107## API
108### cssDeclarationSorter({ order, keepOverrides })
109
110#### order
111Type: `string` or `function`
112Default: `alphabetical`
113Options: `alphabetical`, `smacss`, `concentric-css`
114
115Provide the name of one of the built-in sort orders or a comparison function that is passed to ([`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)). This function receives two declaration names and is expected to return `-1`, `0` or `1` depending on the wanted order.
116
117#### keepOverrides
118Type: `Boolean`
119Default: `false`
120
121To prevent breaking legacy CSS where shorthand declarations override longhand declarations (also taking into account vendor prefixes) this option can enabled. For example `animation-name: some; animation: greeting;` will be kept in this order when `keepOverrides` is `true`.
122
123[PostCSS]: https://github.com/postcss/postcss
124
125[npm]: https://www.npmjs.com/package/css-declaration-sorter
126[npm-badge]: https://tinyshields.dev/npm/css-declaration-sorter.svg
Note: See TracBrowser for help on using the repository browser.