<commit_before>/*
 * grunt-webpcss
 * https://github.com/lexich/webpcss-transform
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */
'use strict';

var postcss = require('postcss');
var _ = require('lodash');

function processor (_options){
  var options = _.defaults(_options || {},{
    baseClass: ".webp",
    replace_from: /\.(png|jpg|jpeg)/,
    replace_to: ".webp"
  });
  return function (css){
    var nodes = [];
    css.eachDecl(function(decl, data) {
      if(decl.prop.indexOf("background") === 0 && decl.value.indexOf("url") >= 0 ){
        var selector = "";
        for(var index in decl.parent.selectors){
          if(!!selector){ selector += ", "; }
          selector += options.baseClass + " " + decl.parent.selectors[index].trim();
        }
        var rx = options.replace_from;
        if(!_.isRegExp(options.replace_from)){ rx = new RegExp(rx); }
        var value = decl.value.replace(rx,options.replace_to);
        if(value === decl.value){ return; }
        var prop = decl.prop;
        if( value.indexOf(",") === -1 && /url[ ]*\((.+)\)/g.exec(value) ){
          value = "url(" + RegExp.$1 + ")";
          prop = "background-image";
        }
        var new_decl = decl.parent.clone({selector: selector});
        new_decl.each(function (decl, i) {
            new_decl.remove(i);
        });
        new_decl.append({
          prop:prop,
          value: value,
          semicolon: true
        });
        nodes.push(new_decl);
      }
    });
    for(var n=0; n < nodes.length; n++){
      css.append(nodes[n]);
    }
  };
}

function transform (data, options){
  return postcss(processor(options)).process(data).css;
}

module.exports.processor = processor;
module.exports.transform = transform;<commit_msg>refactoring<commit_after>/*
 * grunt-webpcss
 * https://github.com/lexich/webpcss-transform
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */
'use strict';

var postcss = require("postcss");
var _ = require("lodash");

function processor (_options){
  var options = _.defaults(_options || {}, {
    baseClass: ".webp",
    replace_from: /\.(png|jpg|jpeg)/,
    replace_to: ".webp"
  });
  return function (css){
    var nodes = [];
    css.eachDecl(function(decl, data) {
      if(decl.prop.indexOf("background") === 0 && decl.value.indexOf("url") >= 0 ){
        var selector = _.map(decl.parent.selectors, function(sel, i){
          return options.baseClass + " " + sel;
        }).join(", ");
        var rx = _.isRegExp(options.replace_from) ? options.replace_from : new RegExp(rx);
        var value = decl.value.replace(rx, options.replace_to);
        if(value === decl.value){ return; }
        if( value.indexOf(",") === -1 && /url[ ]*\((.+)\)/g.exec(value) ){
          value = "url(" + RegExp.$1 + ")";
        } else { return; }
        var new_decl = decl.parent.clone({selector: selector});
        new_decl.each(function (decl, i) { new_decl.remove(i); });
        new_decl.append({prop: "background-image", value: value, semicolon: true});
        nodes.push(new_decl);
      }
    });
    nodes.forEach(function(decl){ css.append(decl); });
  };
}

function transform (data, options){
  return postcss(processor(options)).process(data).css;
}

module.exports.processor = processor;
module.exports.transform = transform;
{'fraction_non_alphanumeric': 0.18170878459687123, 'fraction_numerical': 0.005114320096269555, 'mean_word_length': 2.7317620650953987, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '386667', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1047, 'n_words': 210}