<commit_before>'use strict';
var Promise = require('pinkie-promise');
var Route = require('./route');
var methods = [
	'HEAD',
	'OPTIONS',
	'GET',
	'PUT',
	'PATCH',
	'POST',
	'DELETE'
];

function Router() {
	if (!(this instanceof Router)) {
		return new Router();
	}

	this._stack = [];
}

methods.forEach(function (method) {
	method = method.toLowerCase();

	Router.prototype[method] = function (path) {
		var middleware = Array.prototype.slice.call(arguments, 1);

		this.register(path, [method], middleware);
		return this;
	};
});

Router.prototype.del = Router.prototype.delete;

Router.prototype.register = function (path, methods, middleware) {
	var stack = this._stack;
	var route = new Route(path, methods, middleware);

	if (methods.length || !stack.length) {
		var added = false;

		if (!route.paramNames.length) {
			var routeNestingLevel = route.path.toString().split('/').length;

			added = stack.some(function (m, i) {
				var mNestingLevel = m.path.toString().split('/').length;
				var isParamRoute = Boolean(m.paramNames.length);
				if (routeNestingLevel === mNestingLevel && isParamRoute) {
					return stack.splice(i, 0, route);
				}
			});
		}

		if (!added) {
			stack.push(route);
		}
	} else {
		stack.some(function (m, i) {
			if (!m.methods.length && i === stack.length - 1) {
				return stack.push(route);
			} else if (m.methods.length) {
				if (stack[i - 1]) {
					return stack.splice(i, 0, route);
				}

				stack.unshift(route);
			}
		});
	}

	return route;
};

Router.prototype.routes = function () {
	var router = this;

	return function () {
		var path = this.path;
		var matched = router.match(path, this.method);
		var next = Promise.resolve();

		this.matched = matched.path;

		if (matched.pathAndMethod.length) {
			var i = matched.pathAndMethod.length;

			while (matched.route && i--) {
				var route = matched.pathAndMethod[i];
				var ii = route.stack.length;<commit_msg>fix to lower case issue<commit_after>'use strict';
var Promise = require('pinkie-promise');
var Route = require('./route');
var methods = [
	'HEAD',
	'OPTIONS',
	'GET',
	'PUT',
	'PATCH',
	'POST',
	'DELETE'
];

function Router() {
	if (!(this instanceof Router)) {
		return new Router();
	}

	this._stack = [];
}

methods.forEach(function (method) {
	method = method.toLowerCase();

	Router.prototype[method] = function (path) {
		var middleware = Array.prototype.slice.call(arguments, 1);

		this.register(path, [method], middleware);
		return this;
	};
});

Router.prototype.del = Router.prototype.delete;

Router.prototype.register = function (path, methods, middleware) {
	var stack = this._stack;
	var route = new Route(path, methods, middleware);

	if (methods.length || !stack.length) {
		var added = false;

		if (!route.paramNames.length) {
			var routeNestingLevel = route.path.toString().split('/').length;

			added = stack.some(function (m, i) {
				var mNestingLevel = m.path.toString().split('/').length;
				var isParamRoute = Boolean(m.paramNames.length);
				if (routeNestingLevel === mNestingLevel && isParamRoute) {
					return stack.splice(i, 0, route);
				}
			});
		}

		if (!added) {
			stack.push(route);
		}
	} else {
		stack.some(function (m, i) {
			if (!m.methods.length && i === stack.length - 1) {
				return stack.push(route);
			} else if (m.methods.length) {
				if (stack[i - 1]) {
					return stack.splice(i, 0, route);
				}

				stack.unshift(route);
			}
		});
	}

	return route;
};

Router.prototype.routes = function () {
	var router = this;

	return function () {
		var path = this.path;
		var matched = router.match(path, this.method.toLowerCase());
		var next = Promise.resolve();

		this.matched = matched.path;

		if (matched.pathAndMethod.length) {
			var i = matched.pathAndMethod.length;

			while (matched.route && i--) {
				var route = matched.pathAndMethod[i];
				var ii = route.stack.length;
{'fraction_non_alphanumeric': 0.16675284384694933, 'fraction_numerical': 0.0025853154084798345, 'mean_word_length': 3.436926605504587, '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': '2024731', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1305, 'n_words': 299}