<commit_before>'use strict';

var dollars = require('dollars');

/**
 * Roete (Route) matching.
 *
 * @constructor
 * @param {String} url URL we should trigger upon.
 * @api public
 */
function Roete(url) {
  if (!this) return new Roete(url);

  this.parsers = {};    // Parameter parsers.
  this.methods = {};    // HTTP methods we handle.
  this.params = [];     // Name of the parsers.
  this.path = null;     // The compiled Regular Expression.

  if (url) this.parse(url);
}

/**
 * Add a new parameter parser.
 *
 * @param {String} name Name of the param that we should parse.
 * @param {Function} fn Parser method.
 * @returns {Roete}
 * @api public
 */
Roete.prototype.param = function param(name, fn) {
  this.parsers[name] = fn;
  return this;
};

/**
 * Transform a given URL to a regular expression so we can match against
 * incoming URL's.
 *
 * @param {String} url The URL or Regular-like-Expression we should match.
 * @returns {Roete}
 * @api public
 */
Roete.prototype.parse = function parse(url) {
  if (url.charAt(url.length - 1) === '/') url = url.slice(0, -1);
  if (url.charAt(0) === '/') url = url.slice(1);
  url = url.split('/');

  var roete = this
    , slash = '\\/';

  roete.path = new RegExp('^'+ slash + dollars.array.map(url, function each(frag) {
    return frag.replace(/\{([^\{]+?)\}/g, function replace(match, key) {
      roete.params.push(key);

      return '([a-zA-Z0-9-_~\\.%]+)';
    });
  }).join(slash) + slash);

  return roete;
};

/**
 * Check if the route is matching the given URL.
 *
 * @param {String} url Pathname we need to match.
 * @param {String} method HTTP method we accept.
 * @returns {String|Undefined} Matches URL.
 * @api public
 */
Roete.prototype.match = function matching(url, method) {
  if (url.charAt(url.length - 1) !== '/') url = url +'/';
  if (url.charAt(0) !== '/') url = '/'+ url;

  var slices = this.path.exec(url)
    , roete = this
    , match;

  if (slices) match = new Match(slices, url, roete.methods[method]);
  if (!slices || (method && !(method in roete.methods))) return;
  if (slices.length === 1) return match;

  return slices.slice(1).reduce(function reduce(memo, arg, index) {
    var param = roete.params[index];

    match.params[param] = roete.parsers[param]<commit_msg>[fix] Move the method check to the Application<commit_after>'use strict';

var dollars = require('dollars');

/**
 * Roete (Route) matching.
 *
 * @constructor
 * @param {String} url URL we should trigger upon.
 * @api public
 */
function Roete(url) {
  if (!this) return new Roete(url);

  this.parsers = {};    // Parameter parsers.
  this.methods = {};    // HTTP methods we handle.
  this.params = [];     // Name of the parsers.
  this.path = null;     // The compiled Regular Expression.

  if (url) this.parse(url);
}

/**
 * Add a new parameter parser.
 *
 * @param {String} name Name of the param that we should parse.
 * @param {Function} fn Parser method.
 * @returns {Roete}
 * @api public
 */
Roete.prototype.param = function param(name, fn) {
  this.parsers[name] = fn;
  return this;
};

/**
 * Transform a given URL to a regular expression so we can match against
 * incoming URL's.
 *
 * @param {String} url The URL or Regular-like-Expression we should match.
 * @returns {Roete}
 * @api public
 */
Roete.prototype.parse = function parse(url) {
  if (url.charAt(url.length - 1) === '/') url = url.slice(0, -1);
  if (url.charAt(0) === '/') url = url.slice(1);
  url = url.split('/');

  var roete = this
    , slash = '\\/';

  roete.path = new RegExp('^'+ slash + dollars.array.map(url, function each(frag) {
    return frag.replace(/\{([^\{]+?)\}/g, function replace(match, key) {
      roete.params.push(key);

      return '([a-zA-Z0-9-_~\\.%]+)';
    });
  }).join(slash) + slash);

  return roete;
};

/**
 * Check if the route is matching the given URL.
 *
 * @param {String} url Pathname we need to match.
 * @param {String} method HTTP method we accept.
 * @returns {String|Undefined} Matches URL.
 * @api public
 */
Roete.prototype.match = function matching(url, method) {
  if (url.charAt(url.length - 1) !== '/') url = url +'/';
  if (url.charAt(0) !== '/') url = '/'+ url;

  var slices = this.path.exec(url)
    , roete = this
    , match;

  if (slices) match = new Match(slices, url, roete.methods[method]);
  if (!slices || slices.length === 1) return match;

  return slices.slice(1).reduce(function reduce(memo, arg, index) {
    var param = roete.params[index];

    match.params[param] = roete.parsers[param]
{'fraction_non_alphanumeric': 0.1766009306448039, 'fraction_numerical': 0.004874806115665854, 'mean_word_length': 3.088768115942029, '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': '28778', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1525, 'n_words': 452}