How to use the list function from postcss

Find comprehensive JavaScript postcss.list code examples handpicked from public code repositorys.

postcss.list is a utility function in PostCSS that converts a string or an array to a list of space-separated tokens.

71
72
73
74
75
76
77
78
79
80
    }
  };

  root.walkDecls((decl) => {
    if (!decl.value || ignoreList.includes(decl.prop)) return;
    const values = postcss.list.space(decl.value);
    if (!values?.length) return;
    values.forEach((value) => handleValue(decl, value));
  });
};
fork icon0
star icon0
watch icon1

344
345
346
347
348
349
350
351
352
353
    return (0, _getLastNode2.default)(props, prop + '-' + d);
}).map(function (node) {
    return node ? node.value : null;
});
var filteredValues = values.filter(Boolean);
var lastNodeValue = _postcss.list.space(lastNode.value)[i];
values[directions.indexOf(lastNode.prop)] = lastNodeValue;
var value = (0, _minifyTrbl2.default)(values.join(' '));
if (filteredValues[0] === filteredValues[1] && filteredValues[1] === filteredValues[2]) {
    value = filteredValues[0];
fork icon0
star icon0
watch icon1

+ 23 other calls in file

How does postcss.list work?

The postcss.list module provides utilities to manipulate and traverse CSS nodes and their lists in PostCSS, a tool for transforming CSS with JavaScript plugins. It exports methods to filter, insert, remove, and iterate through lists of nodes in various ways, such as by node type, selector, or index.

11
12
13
14
15
16
17
18
19
20
21
22
23
24


var _postcss = require('postcss');


function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }


var space = _postcss.list.space;


exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
    var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

fork icon0
star icon0
watch icon1

+ 3 other calls in file

13
14
15
16
17
18
19
20
21
22
23
24
25
26


var _commentParser2 = _interopRequireDefault(_commentParser);


function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }


const { space } = _postcss.list;


exports.default = (0, _postcss.plugin)('postcss-discard-comments', (opts = {}) => {
    const remover = new _commentRemover2.default(opts);

fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
11
const postcss = require("postcss");

const css = `
.foo, .bar {
color: red;
}
`;

const rule = postcss.parse(css).first;
const selectors = postcss.list.comma(rule.selector);
console.log(selectors); // ['foo', 'bar']

2
3
4
5
6
7
8
9
10
11
12
13
14
15
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }


function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }


var _require = require('postcss'),
    list = _require.list;


var OldSelector = require('./old-selector');


var Prefixer = require('./prefixer');
fork icon0
star icon0
watch icon0