source: trip-planner-front/node_modules/css-declaration-sorter/readme.md@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.6 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[![LGTM Grade][lgtm-badge]][lgtm]
5[![npm][npm-badge]][npm]
6
7A 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.
8
9Check out [the Prettier plugin](https://github.com/Siilwyn/prettier-plugin-css-order) for usage with a variety of file formats.
10
11## Niceness
12- Up-to-date CSS properties fetched from the [MDN Compatibility Data](https://github.com/mdn/browser-compat-data/) project.
13- Choose your wanted order or provide your own.
14- Nested rules sorting support.
15- 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).
16- Thought-out sorting orders out of the box, **approved by their authors**.
17
18## Alphabetical example
19Input:
20```css
21body {
22 display: block;
23 animation: none;
24 color: #C55;
25 border: 0;
26}
27```
28
29Output:
30```css
31body {
32 animation: none;
33 border: 0;
34 color: #C55;
35 display: block;
36}
37```
38
39## Built-in sorting orders
40- Alphabetical
41`alphabetical`
42*Default, order in a simple alphabetical manner from a - z.*
43
44- [SMACSS](http://smacss.com/book/formatting#grouping)
45`smacss`
46*Order from most important, flow affecting properties, to least important properties.*
47 1. Box
48 2. Border
49 3. Background
50 4. Text
51 5. Other
52
53- [Concentric CSS](https://github.com/brandon-rhodes/Concentric-CSS)
54`concentric-css`
55*Order properties applying outside the box model, moving inward to intrinsic changes.*
56 1. Positioning
57 2. Visibility
58 3. Box model
59 4. Dimensions
60 5. Text
61
62## Usage
63Following the PostCSS plugin guidelines, this package depends on PostCSS as a peer dependency:
64`npm install postcss css-declaration-sorter --save-dev`
65
66### CLI
67This 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.
68
69Piping out result from file:
70`postcss input.css --use css-declaration-sorter | cat`
71
72Sorting multiple files by overwriting:
73`postcss *.css --use css-declaration-sorter --replace --no-map`
74
75Sorting all files in a directory with SCSS syntax using [postcss-scss](https://github.com/postcss/postcss-scss) by overwriting:
76`postcss ./src/**/*.scss --syntax postcss-scss --use css-declaration-sorter --replace --no-map`
77
78Sorting all files in the directory with SCSS syntax and SMACSS order by overwriting, using `package.json` configuration:
79```json
80"postcss": {
81 "syntax": "postcss-scss",
82 "map": false,
83 "plugins": {
84 "css-declaration-sorter": { "order": "smacss" }
85 }
86}
87```
88
89`postcss ./src/**/*.scss --replace --config package.json`
90
91### Vanilla JS
92```js
93import postcss from 'postcss';
94import cssDeclarationSorter from 'css-declaration-sorter';
95
96postcss([cssDeclarationSorter({ order: 'smacss' })])
97 .process('a { color: hyperblue; display: block; }', { from: undefined })
98 .then(result => console.log(
99 result.css === 'a { display: block; color: hyperblue; }'
100 ));
101```
102___
103
104**[View more usage examples](/examples) in combination with other tools.**
105
106___
107
108## API
109### cssDeclarationSorter({ order, keepOverrides })
110
111#### order
112Type: `string` or `function`
113Default: `alphabetical`
114Options: `alphabetical`, `smacss`, `concentric-css`
115
116Provide 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.
117
118#### keepOverrides
119Type: `Boolean`
120Default: `false`
121
122To 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`.
123
124[PostCSS]: https://github.com/postcss/postcss
125
126[lgtm]: https://lgtm.com/projects/g/Siilwyn/css-declaration-sorter/
127[lgtm-badge]: https://tinyshields.dev/lgtm/grade/javascript/g/Siilwyn/css-declaration-sorter.svg
128[npm]: https://www.npmjs.com/package/css-declaration-sorter
129[npm-badge]: https://tinyshields.dev/npm/css-declaration-sorter.svg
Note: See TracBrowser for help on using the repository browser.