Sha256: 980a801f5bae59d6a7de19e4aa9540e8b936c5739146c9cff2cf4852c2ab8035

Contents?: true

Size: 1.05 KB

Versions: 52

Compression:

Stored size: 1.05 KB

Contents

module.exports = Negotiator;
Negotiator.Negotiator = Negotiator;

function Negotiator(request) {
  if (!(this instanceof Negotiator)) return new Negotiator(request);
  this.request = request;
}

var set = { charset: 'accept-charset',
            encoding: 'accept-encoding',
            language: 'accept-language',
            mediaType: 'accept' };


function capitalize(string){
  return string.charAt(0).toUpperCase() + string.slice(1);
}

Object.keys(set).forEach(function (k) {
  var header = set[k],
      method = require('./'+k+'.js'),
      singular = k,
      plural = k + 's';

  Negotiator.prototype[plural] = function (available) {
    return method(this.request.headers[header], available);
  };

  Negotiator.prototype[singular] = function(available) {
    var set = this[plural](available);
    if (set) return set[0];
  };

  // Keep preferred* methods for legacy compatibility
  Negotiator.prototype['preferred'+capitalize(plural)] = Negotiator.prototype[plural];
  Negotiator.prototype['preferred'+capitalize(singular)] = Negotiator.prototype[singular];
})

Version data entries

52 entries across 18 versions & 3 rubygems

Version Path
blackboard-3.1.9 lib/site_template/node_modules/engine.io/node_modules/negotiator/lib/negotiator.js
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-index/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/compression/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/compression/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-index/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/compression/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-index/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/compression/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-index/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-index/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/compression/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/compression/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-index/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js