Takes eliminate :replace and :before rules.
 Returns hash, that maps middleware classes to their dependencies
504942
def normalize_rules(rules)
      deps          = Hash.new { |h, k| h[k] = [] }
      substitutions = {}

      # replace before with after on oposite direction and build the
      # substitutions dictionary
      rules.each do |middleware_class, middleware_rules|
        deps[middleware_class].concat(middleware_rules[:after])
        middleware_rules[:before].each do |dependent_class|
          deps[dependent_class] << middleware_class
        end
        middleware_rules[:replace].each do |replaced|
          substitutions[replaced] = middleware_class
        end
      end

      # replace the middleware to be substituted
      substitutions.each do |old, new|
        deps[new].concat(deps[old])
        deps.delete(old)
      end

      # ignore deps, that are not present in the stack
      deps.each do |middleware_class, middleware_deps|
        middleware_deps.reject! { |dep| !deps.has_key?(dep) }
      end

      return deps.delete_if {|klass, _| klass.nil? }
    end
101286
function sanitize (fn) {
  return function (/* path, ...middleware */) {
    var middleware = []
    var startindex = 0
    var endindex = arguments.length
    var path
    var options

    if (typeof arguments[0] === 'string') {
      path = arguments[0]
      startindex = 1
    }

    if (typeof arguments[arguments.length - 1] === 'object') {
      endindex = arguments.length - 1
      options = arguments[endindex]
    }

    // Concat all the middleware functions.
    for (var i = startindex; i < endindex; i++) {
      middleware.push(arguments[i])
    }

    middleware = flatten(middleware)

    if (middleware.length === 0) {
      throw new TypeError('Expected a function but got no arguments')
    }

    if (middleware.length === 1) {
      middleware = middleware[0]
    } else {
      middleware = compose(middleware)
    }

    fn.call(this, path, middleware, extend({}, this._options, options))

    return this
  }
}
34539
def api_hash(replace = nil)
      self.replace = replace unless replace.nil?
      {
        url:          href,
        description:  description,
        extended:     extended,
        tags:         tag.join(" "),
        replace:      replace,
        shared:       shared,
        toread:       toread
      }.select { |key, value| ! value.nil? }
    end
302166
def filter!(keys, params, options={:recursive => true})  # :nodoc:
      case params
      when Hash, ParamsHash
        params.keys.each do |k, v|
          unless (keys.include?(k) or Github::Validations::VALID_API_KEYS.include?(k))
            params.delete(k)
          else
            filter!(keys, params[k]) if options[:recursive]
          end
        end
      when Array
        params.map! do |el|
          filter!(keys, el) if options[:recursive]
        end
      else
        params
      end
      return params
    end
401956
function before(ctx) {
  var fn = lookup(ctx.operation, 'middleware', 'before');
  var prefix = describe(ctx);

  if (fn) {
    return fn(ctx);
  } else {
    debug(prefix + 'before middleware disabled (not defined)');
  }
}
373283
def replace_symbols(script_name, *args)
    args_new = []
    args_copy = args.clone

    url = args[0].clone
    modifiers = args_copy[1]
    if modifiers.class == Hash
      modifiers.delete_if do |key, value|
        delete = url.include? (":" + key.to_s)
        if delete
          url.sub!( (":" + key.to_s), value.to_s )
        end
        delete
      end
    end

    i = 1
    result = [url]
    while args_copy[i]
      unless args_copy[i].empty?

        if args_copy[i].class == Array
          value = args_copy[i]
        else
          value = [args_copy[i]]
        end

        if args_copy[i] != '/?' && url =~ /\*/
          url.sub!("*", value.join(''))
        else
          result.concat(value)
        end

      end
      i+= 1
    end
    result
  end
892536
function replace_params(params) {
	return function replace_params_(match, key) {
		if(params && params.hasOwnProperty(key)) {
			var value = params[key];
			delete params[key];
			return value;
		}
		return ':' + key;
	};
}
651923
def middleware
      mw = Hash.new { |e, m| e[m] = [] }
      mw["development"].concat([::Rack::ShowExceptions, ::Rack::Lint])
      require 'hanami/assets/static'
      mw["development"].push(::Hanami::Assets::Static)
      mw
    end
254983
def normalize(path, extra=nil, params={})
      if extra.is_a?(Hash) and params.empty?
        params = extra
        extra = nil
      end

      path = "#{path}/#{extra}" if extra
      path = "/#{path}" unless path[0] == '/'

      query = default_query.merge params

      params[:query] = query unless query.empty?
      params = default_params.merge params

      [path, extra, params]
    end
684526
def method_missing meth, *args, &block
      meth_s = meth.to_s
      if @method && meth_s =~ API_REGEX

        if meth_s.end_with?('!')
          # `foo! bar' is syntactic sugar for `foo.! bar'
          self[meth_s[0...-1]].!(args[0] || {})

        else
          # chain the method name onto URL path
          self[meth_s]
        end
      else
        super
      end
    end
1203326
def dependency_to_spec(dep)
      # #to_spec doesn't allow prereleases unless the requirement is
      # for a prerelease. Just use the last valid spec if possible.
      spec = dep.to_spec || dep.to_specs.last
      raise Error.new("Cannot find a gem to satisfy #{dep}") unless spec
      spec
    rescue ::Gem::LoadError => ex
      raise Error.new("Cannot find a gem to satisfy #{dep}: #{ex}")
    end
1128824
function stripLoaderPrefix(str) {
	if (typeof str === 'string') {
		str = str.replace(
			/(?:(\()|(^|\b|@))(\.\/~|\.{0,2}\/(?:[^\s]+\/)?node_modules)\/\w+-loader(\/[^?!]+)?(\?\?[\w_.-]+|\?({[\s\S]*?})?)?!/g,
			'$1'
		);
		str = str.replace(/(\.?\.?(?:\/[^/ ]+)+)\s+\(\1\)/g, '$1');
		str = replaceAll(str, process.cwd(), '.');
		return str;
	}
	return str;
}
582298
def replace_matcher(part, new_matcher)
      key = key_for(part)
      @components[key] = new_matcher.with_attribute(:name => /\(#{key}\)/)
    end
654370
function findPartials(source, source_path, options, deps) {
  var reg = /({>\s?")([^"{}]+)("[\s\S]*?\/})/g, // matches dust partial syntax
    result = null, partial,
    dep, name, replace;

  // search source & add a dependency for each match
  while ((result = reg.exec(source)) !== null) {
    partial = {
      prefix: result[1],
      name: result[2],
      suffix: result[3]
    };

    // add to dependencies
    name = addDustDependency(partial.name, source_path, options, deps);

    // retrieve newest dependency
    dep = deps[deps.length - 1];

    // log
    log(options, 'found partial dependency "' + partial.name + '"');

    // if the partial has been renamed, update the name in the template
    if (name != partial.name) {
      log(options, 'renaming partial "' + partial.name + '" to "' + name + '"')

      // build replacement for partial tag
      replace = partial.prefix + name + partial.suffix;

      // replace the original partial path with the new "absolute" path (relative to root)
      source = source.substring(0, result.index) + replace + source.substring(result.index + result[0].length);

      // update regex index
      reg.lastIndex += (replace.length - result[0].length);
    }
  }

  return source;
}
1153309
function replacePatterns(token, replacements, measureThreshold) {
    var result = attemptReplacePatterns(token, replacements, measureThreshold);
    token = result == null ? token : result;
    
    return token;
}
555547
def apply_replacements(output)
      replace_patterns.reduce(output) do |output, replacement_pattern|
        replacement_pattern.replace(output)
      end
    end
653141
def before_all(key, options)
      required(key) if (options.has_key?(:required) and options[:required] == true)
      if options.has_key?(:dependencies)
        dependencies(key, options[:dependencies])
      elsif options.has_key?(:dependency)
        dependency(key, options[:dependency])
      end
    end