<commit_before>var postcss = require('postcss');

var fs = require('fs');
var path = require('path');
var url = require('url');

var R_ASSET = /asset\((.*?)([^\s'"]+)(.*?)\)/;

module.exports = function (options) {
  options.loadPaths = options.loadPaths || [];
  options.loadPaths.unshift('./');
  return function (css) {
    css.eachDecl(function (decl) {
      if (decl.value.indexOf('asset(') !== 0) return;
      var matches = decl.value.match(R_ASSET);
      var uri = url.parse(matches[2]);
      var pathname = uri.pathname;
      var some = options.loadPaths.some(function (loadPath) {
        uri.pathname = path.normalize('/' + loadPath + pathname);
        return fs.existsSync(options.basePath + uri.pathname);
      });
      if (!some) throw new Error;
      decl.value = 'url(' + matches[1] + url.format(uri) + matches[3] + ')';
    });
  };
};<commit_msg>Extract `resolve` method<commit_after>var postcss = require('postcss');

var fs = require('fs');
var path = require('path');
var url = require('url');

var R_ASSET = /asset\((.*?)([^\s'"]+)(.*?)\)/;

module.exports = function (options) {
  options.loadPaths = options.loadPaths || [];
  options.loadPaths.unshift('./');

  function resolve(fn) {
    var uri = url.parse(fn);
    var pathname = uri.pathname;
    var some = options.loadPaths.some(function (loadPath) {
      uri.pathname = path.normalize('/' + loadPath + pathname);
      return fs.existsSync(options.basePath + uri.pathname);
    });
    if (!some) throw new Error;
    return url.format(uri);
  }

  return function (css) {
    css.eachDecl(function (decl) {
      if (decl.value.indexOf('asset(') !== 0) return;
      var matches = decl.value.match(R_ASSET);
      decl.value = 'url(' + matches[1] + resolve(matches[2]) + matches[3] + ')';
    });
  };
};
{'fraction_non_alphanumeric': 0.1965478841870824, 'fraction_numerical': 0.004454342984409799, 'mean_word_length': 3.330120481927711, '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': '6969029', 'n_tokens_mistral': 603, 'n_tokens_neox': 599, 'n_words': 126}