11cb0ef41Sopenharmony_ci/*!
21cb0ef41Sopenharmony_ci * negotiator
31cb0ef41Sopenharmony_ci * Copyright(c) 2012 Federico Romero
41cb0ef41Sopenharmony_ci * Copyright(c) 2012-2014 Isaac Z. Schlueter
51cb0ef41Sopenharmony_ci * Copyright(c) 2015 Douglas Christopher Wilson
61cb0ef41Sopenharmony_ci * MIT Licensed
71cb0ef41Sopenharmony_ci */
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci'use strict';
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_civar preferredCharsets = require('./lib/charset')
121cb0ef41Sopenharmony_civar preferredEncodings = require('./lib/encoding')
131cb0ef41Sopenharmony_civar preferredLanguages = require('./lib/language')
141cb0ef41Sopenharmony_civar preferredMediaTypes = require('./lib/mediaType')
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci/**
171cb0ef41Sopenharmony_ci * Module exports.
181cb0ef41Sopenharmony_ci * @public
191cb0ef41Sopenharmony_ci */
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cimodule.exports = Negotiator;
221cb0ef41Sopenharmony_cimodule.exports.Negotiator = Negotiator;
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci/**
251cb0ef41Sopenharmony_ci * Create a Negotiator instance from a request.
261cb0ef41Sopenharmony_ci * @param {object} request
271cb0ef41Sopenharmony_ci * @public
281cb0ef41Sopenharmony_ci */
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_cifunction Negotiator(request) {
311cb0ef41Sopenharmony_ci  if (!(this instanceof Negotiator)) {
321cb0ef41Sopenharmony_ci    return new Negotiator(request);
331cb0ef41Sopenharmony_ci  }
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  this.request = request;
361cb0ef41Sopenharmony_ci}
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciNegotiator.prototype.charset = function charset(available) {
391cb0ef41Sopenharmony_ci  var set = this.charsets(available);
401cb0ef41Sopenharmony_ci  return set && set[0];
411cb0ef41Sopenharmony_ci};
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciNegotiator.prototype.charsets = function charsets(available) {
441cb0ef41Sopenharmony_ci  return preferredCharsets(this.request.headers['accept-charset'], available);
451cb0ef41Sopenharmony_ci};
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ciNegotiator.prototype.encoding = function encoding(available) {
481cb0ef41Sopenharmony_ci  var set = this.encodings(available);
491cb0ef41Sopenharmony_ci  return set && set[0];
501cb0ef41Sopenharmony_ci};
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ciNegotiator.prototype.encodings = function encodings(available) {
531cb0ef41Sopenharmony_ci  return preferredEncodings(this.request.headers['accept-encoding'], available);
541cb0ef41Sopenharmony_ci};
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ciNegotiator.prototype.language = function language(available) {
571cb0ef41Sopenharmony_ci  var set = this.languages(available);
581cb0ef41Sopenharmony_ci  return set && set[0];
591cb0ef41Sopenharmony_ci};
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ciNegotiator.prototype.languages = function languages(available) {
621cb0ef41Sopenharmony_ci  return preferredLanguages(this.request.headers['accept-language'], available);
631cb0ef41Sopenharmony_ci};
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ciNegotiator.prototype.mediaType = function mediaType(available) {
661cb0ef41Sopenharmony_ci  var set = this.mediaTypes(available);
671cb0ef41Sopenharmony_ci  return set && set[0];
681cb0ef41Sopenharmony_ci};
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ciNegotiator.prototype.mediaTypes = function mediaTypes(available) {
711cb0ef41Sopenharmony_ci  return preferredMediaTypes(this.request.headers.accept, available);
721cb0ef41Sopenharmony_ci};
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci// Backwards compatibility
751cb0ef41Sopenharmony_ciNegotiator.prototype.preferredCharset = Negotiator.prototype.charset;
761cb0ef41Sopenharmony_ciNegotiator.prototype.preferredCharsets = Negotiator.prototype.charsets;
771cb0ef41Sopenharmony_ciNegotiator.prototype.preferredEncoding = Negotiator.prototype.encoding;
781cb0ef41Sopenharmony_ciNegotiator.prototype.preferredEncodings = Negotiator.prototype.encodings;
791cb0ef41Sopenharmony_ciNegotiator.prototype.preferredLanguage = Negotiator.prototype.language;
801cb0ef41Sopenharmony_ciNegotiator.prototype.preferredLanguages = Negotiator.prototype.languages;
811cb0ef41Sopenharmony_ciNegotiator.prototype.preferredMediaType = Negotiator.prototype.mediaType;
821cb0ef41Sopenharmony_ciNegotiator.prototype.preferredMediaTypes = Negotiator.prototype.mediaTypes;
83