Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

postcss-between

1.0.4 • Public • Published

Between Build Status npm version

PostCSS plugin that handles spacing between blocks for a more readable stylesheet.

Between will only affect the spaces between blocks; selector and in-rule formatting/ordering will remain untouched. Use it as the mastering to perfectionist's mixing, for example.

Usage

npm install postcss-between
const between = require('postcss-between');
postcss([
  between({
    // options
  })
]);

Use with Node 8 or greater. See PostCSS docs for examples for your environment.

Options

Spacing

Types: int

The amount of spacing between different combinations of blocks is adjustable using these options. Each value corresponds to the number of blank lines that will be baked out at the given points.

Option Default Description
spaceRelatedRule 0 rule + related rule; e.g. .foo { } followed by .foo a { }
spaceUnrelatedRule 1 rule + unrelated rule; e.g. .foo { } followed by .bar { }
spaceHeadingBefore 2 anything + heading comment
spaceHeadingAfter 1 heading comment + rule
spaceRelatedAtRule 1 rule or at-rule + related at-rule
spaceUnrelatedAtRule 2 rule or at-rule + unrelated at-rule

headingCommentIdentifiers

Type: Array of strings

Default: [ '---', '===', '___', '+++', '***']

A set of strings that, when found in a comment, mark that comment as a major section heading, which is then spaced accordingly. The spacing of all other comments will remain untouched. To never mark any comments as headings, pass an empty array literal — [] — or null.

breakMultipleSelectors

Type: boolean

Default: false

Set to true in order to force the breaking of multiple selectors to new lines. This is the only time that Between will alter existing block formatting. Fills in a gap when used in conjunction with perfectionist.

In:

a:hovera:focus {}

Out:

a:hover,
a:focus {}

Examples

Selector blocks

Spaces most selector blocks, but keeps related items together.

In:

a {}
a:hovera:focus {}
a[href^="/"] {}
.foo {}
.bar {}
.bar a {}

Out:

a {}
a:hovera:focus {}
a[href^="/"] {}
 
.foo {}
 
.bar {}
.bar a {}

This includes BEM blocks.

In:

.block {}
 
 
.block__element {}
.block__element--modifier {}
 
.another-block {}
 
.no-js .another-block .foo {}

Out:

.block {}
.block__element {}
.block__element--modifier {}
 
.another-block {}
.no-js .another-block .foo {}

Comments

Only mess with comments if the comment is a major section heading. By default, a major section heading contains three or more of -, _, =, +, or * in a row. Override this in the options.

In:

.foo {}
/* ---------- header ---------- */
.header {}
.header__logo {}
.header__cta {}
.nav {}
.nav__item {}
/* ---------- footer ---------- */
.footer__contact {}
.footer__social {}

Out:

.foo {}
 
 
/* ---------- header ---------- */
 
.header {}
.header__logo {}
.header__cta {}
 
.nav {}
.nav__item {}
 
 
/* ---------- footer ---------- */
 
.footer__contact {}
.footer__social {}

Media queries

Media queries are given ample spacing.

In:

.foo {}
.bar {}
@media (min-width: 720px) {
  .baz {}
}

Out:

.foo {}
 
.bar {}
 
 
@media (min-width: 720px) {
  .baz {}
}

Media query spacing tightens up in a BEM block.

In:

.block {}
.block__element {}
@media (min-width: 720px) {
  .block__element--modifier {}
}

Out:

.block {}
.block__element {}
 
@media (min-width: 720px) {
  .block__element--modifier {}
}

Install

npm i postcss-between

DownloadsWeekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

16.5 kB

Total Files

5

Last publish

Collaborators

  • avatar