<commit_before>'use strict';

/* build.js
 * Build CSS from a tree.
 */

const Selector = require('./selector'),
      Property = require('./property'),
      Value = require('./value');

module.exports = exports = Build;

exports.value = function(value, last){
  if (!(value instanceof Value))
    throw new TypeError('value must be a Value object');

  let unit = exports.translator[value.unit];
  if (typeof unit === 'undefined') unit = value.unit;

  return value.value + (value.unit === 'font' ? (last ? '' : unit) : unit || '');
};

exports.property = function(prop, indent){
  if (!(prop instanceof Property))
    throw new TypeError('prop must be a Property object');

  let values = '', index = 0, last = false;
  for (let value of prop.values) {
    last = index === prop.values.length-1;
    values += (exports.value(value, last) + (last ? '' : ' '));
    index++;
  }

  if (typeof indent === 'undefined') indent = 2;
  indent = indent ? ' '.repeat(indent) : '';

  return indent + prop.name + ':' + values + ';\n';
};

exports.selector = function(selector, indent){
  if (!(selector instanceof Selector))
    throw new TypeError('prop must be a Property object');

  let props = '';
  for (let prop of selector.properties) {
    props += (this.property(prop, indent));
  }

  return selector.sel + ' {\n' + props + '}\n\n';
};

exports.translator = {
  'px': 'px ',
  'pixel': 'px ',
  'font': ', '
};

function Build(tree, indent){
  if (!Array.isArray(tree))
    throw new TypeError('tree must be an array of Selector objects');

  let globalStyles = new Selector('*');

  let rendered = '';
  for (let item of tree) {
    if (item instanceof Selector)
      rendered += exports.selector(item, indent);

    if (item instanceof Property)
      globalStyles.add(item);
  }
  if (globalStyles.properties.length) rendered += exports.selector(globalStyles, indent);

  return rendered;
}<commit_msg>Change build case<commit_after>'use strict';

/* build.js
 * Build CSS from a tree.
 */

const Selector = require('./selector'),
      Property = require('./property'),
      Value = require('./value');

module.exports = exports = build;

exports.value = function(value, last){
  if (!(value instanceof Value))
    throw new TypeError('value must be a Value object');

  let unit = exports.translator[value.unit];
  if (typeof unit === 'undefined') unit = value.unit;

  return value.value + (value.unit === 'font' ? (last ? '' : unit) : unit || '');
};

exports.property = function(prop, indent){
  if (!(prop instanceof Property))
    throw new TypeError('prop must be a Property object');

  let values = '', index = 0, last = false;
  for (let value of prop.values) {
    last = index === prop.values.length-1;
    values += (exports.value(value, last) + (last ? '' : ' '));
    index++;
  }

  if (typeof indent === 'undefined') indent = 2;
  indent = indent ? ' '.repeat(indent) : '';

  return indent + prop.name + ':' + values + ';\n';
};

exports.selector = function(selector, indent){
  if (!(selector instanceof Selector))
    throw new TypeError('prop must be a Property object');

  let props = '';
  for (let prop of selector.properties) {
    props += (this.property(prop, indent));
  }

  return selector.sel + ' {\n' + props + '}\n\n';
};

exports.translator = {
  'px': 'px ',
  'pixel': 'px ',
  'font': ', '
};

function build(tree, indent){
  if (!Array.isArray(tree))
    throw new TypeError('tree must be an array of Selector objects');

  let globalStyles = new Selector('*');

  let rendered = '';
  for (let item of tree) {
    if (item instanceof Selector)
      rendered += exports.selector(item, indent);

    if (item instanceof Property)
      globalStyles.add(item);
  }
  if (globalStyles.properties.length) rendered += exports.selector(globalStyles, indent);

  return rendered;
}
{'fraction_non_alphanumeric': 0.1684100418410042, 'fraction_numerical': 0.0015690376569037657, 'mean_word_length': 3.421965317919075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4839491', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1143, 'n_words': 358}