{"size": 639, "ext": "js", "max_stars_repo_path": "packages/postcss-ordered-values/src/rules/columns.js", "max_stars_repo_name": "jezemery/cssnano", "max_stars_repo_stars_event_min_datetime": "2018-06-11T08:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T09:34:37.000Z", "max_issues_repo_path": "packages/postcss-ordered-values/src/rules/columns.js", "max_issues_repo_name": "jezemery/cssnano", "max_issues_repo_issues_event_min_datetime": "2018-06-10T23:44:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T22:50:18.000Z", "max_forks_repo_path": "packages/postcss-ordered-values/src/rules/columns.js", "max_forks_repo_name": "jezemery/cssnano", "max_forks_repo_forks_event_min_datetime": "2018-06-13T12:21:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T19:18:07.000Z"}
{"max_stars_count": 1790, "max_issues_count": 800, "max_forks_count": 199, "avg_line_length": 22.0344827586, "max_line_length": 67, "alphanum_fraction": 0.5680751174}
import { unit } from 'postcss-value-parser';

function hasUnit(value) {
  const parsedVal = unit(value);
  return parsedVal && parsedVal.unit !== '';
}

export default (columns) => {
  const widths = [];
  const other = [];
  columns.walk((node) => {
    const { type, value } = node;
    if (type === 'word') {
      if (hasUnit(value)) {
        widths.push(value);
      } else {
        other.push(value);
      }
    }
  });

  // only transform if declaration is not invalid or a single value
  if (other.length === 1 && widths.length === 1) {
    return `${widths[0].trimStart()} ${other[0].trimStart()}`;
  }

  return columns;
};
