source: frontend/node_modules/postcss-ordered-values/src/rules/columns.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 902 bytes
Line 
1'use strict';
2const { unit } = require('postcss-value-parser');
3
4/**
5 * @param {string} value
6 * @return {boolean}
7 */
8function hasUnit(value) {
9 const parsedVal = unit(value);
10 return parsedVal && parsedVal.unit !== '';
11}
12
13/**
14 * @param {import('postcss-value-parser').ParsedValue} columns
15 * @return {import('postcss-value-parser').ParsedValue | string}
16 */
17module.exports = (columns) => {
18 /** @type {string[]} */
19 const widths = [];
20 /** @type {string[]} */
21 const other = [];
22 columns.walk((node) => {
23 const { type, value } = node;
24 if (type === 'word') {
25 if (hasUnit(value)) {
26 widths.push(value);
27 } else {
28 other.push(value);
29 }
30 }
31 });
32
33 // only transform if declaration is not invalid or a single value
34 if (other.length === 1 && widths.length === 1) {
35 return `${widths[0].trimStart()} ${other[0].trimStart()}`;
36 }
37
38 return columns;
39};
Note: See TracBrowser for help on using the repository browser.