github.com/cloudcredo/cloudrocker@v0.0.0-20160108110610-1320f8cc2dfd/sample-apps/node/node_modules/express/lib/router/match.js (about)

     1  /**
     2   * Module dependencies.
     3   */
     4  
     5  var pathRegexp = require('path-to-regexp');
     6  
     7  /**
     8   * Expose `Layer`.
     9   */
    10  
    11  module.exports = Match;
    12  
    13  function Match(layer, path, params) {
    14    this.layer = layer;
    15    this.params = {};
    16    this.path = path || '';
    17  
    18    if (!params) {
    19      return this;
    20    }
    21  
    22    var keys = layer.keys;
    23    var n = 0;
    24    var prop;
    25    var key;
    26    var val;
    27  
    28    for (var i = 0; i < params.length; i++) {
    29      key = keys[i];
    30      val = decode_param(params[i]);
    31      prop = key
    32        ? key.name
    33        : n++;
    34  
    35      this.params[prop] = val;
    36    }
    37  
    38    return this;
    39  };
    40  
    41  /**
    42   * Decode param value.
    43   *
    44   * @param {string} val
    45   * @return {string}
    46   * @api private
    47   */
    48  
    49  function decode_param(val){
    50    if (typeof val !== 'string') {
    51      return val;
    52    }
    53  
    54    try {
    55      return decodeURIComponent(val);
    56    } catch (e) {
    57      var err = new TypeError("Failed to decode param '" + val + "'");
    58      err.status = 400;
    59      throw err;
    60    }
    61  }