npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@goa/negotiator

v1.0.1

Published

[fork] HTTP Content Negotiation In ES6 Optimised With Google Closure Compiler.

Downloads

242

Readme

@goa/negotiator

npm version

@goa/negotiator is a fork of HTTP Content Negotiation In ES6 And Optimised With A JavaScript Compiler For The Best Performance.

The original module has been updated to be used in @goa/koa: Koa web server compiled with Google Closure Compiler using Depack into a single file library (0 dependencies).

yarn add @goa/negotiator

Table Of Contents

API

The package is available by importing its default function:

import Negotiator from '@goa/negotiator'

class Negotiator

Instances of this class will allow to negotiate languages, charsets, media types and encodings.

constructor(  request: IncomingMessage,): Negotiator

Creates a new instance based on the request from the client.

/* alanode example/ */
import aqt from '@rqt/aqt'
import { createServer } from 'http'
import Negotiator from '@goa/negotiator'

const s = createServer((message, response) => {
  const n = new Negotiator(message)

  const availableEncodings = ['identity', 'gzip']
  console.log('encodings', n.encodings())
  console.log('available encodings', n.encodings(availableEncodings))
  console.log('encoding', n.encoding(availableEncodings), '\n')

  const availableLanguages = ['en', 'es', 'fr']
  console.log('languages', n.languages())
  console.log('available languages', n.languages(availableLanguages))
  console.log('language', n.language(availableLanguages), '\n')

  const availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']
  console.log('charsets', n.charsets())
  console.log('available charsets', n.charsets(availableCharsets))
  console.log('charset', n.charset(availableCharsets), '\n')

  const availableMediaTypes = ['text/html', 'text/plain', 'application/json']
  console.log('media types', n.mediaTypes())
  console.log('available media types', n.mediaTypes(availableMediaTypes))
  console.log('media type', n.mediaType(availableMediaTypes))

  response.end()
})

s.listen(0, async () => {
  const url = `http://localhost:${s.address().port}`
  await aqt(url, {
    headers: {
      'accept-encoding': 'gzip, compress;q=0.2, identity;q=0.5',
      'accept-charset': 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2',
      'accept-language': 'en;q=0.8, es, pt',
      accept: 'text/html, application/*;q=0.2, image/jpeg;q=0.8',
    },
  })
  s.close()
})
encodings [ 'gzip', 'deflate', 'identity' ]
available encodings [ 'gzip', 'identity' ]
encoding gzip 

languages [ 'es', 'pt', 'en' ]
available languages [ 'es', 'en' ]
language es 

charsets [ 'utf-8', 'iso-8859-1', 'utf-7' ]
available charsets [ 'utf-8', 'iso-8859-1' ]
charset utf-8 

media types [ 'text/html', 'image/jpeg', 'application/*' ]
available media types [ 'text/html', 'application/json' ]
media type text/html

_goa.Negotiator: HTTP Content Negotiation In ES6.

| Name | Type | Description | | --------------- | -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | | charset* | function(!Array<string>=): string | Returns the most preferred charset from the client. | | charsets* | function(!Array<string>=): !Array<string> | Returns an array of preferred charsets ordered by the client preference. | | encoding* | function(!Array<string>=): string | Returns the most preferred encoding from the client. | | encodings* | function(!Array<string>=): !Array<string> | Returns an array of preferred encodings ordered by the client preference. | | language* | function(!Array<string>=): string | Returns the most preferred language from the client. | | languages* | function(!Array<string>=): !Array<string> | Returns an array of preferred languages ordered by priority from a list of available languages. | | mediaType* | function(!Array<string>=): string | Returns the most preferred media type from the client. | | mediaTypes* | function(!Array<string>=): !Array<string> | Returns an array of preferred media types ordered by priority from a list of available media types. |

Copyright

The original programming work, documentation and NPM package by Federico Romero, Isaac Z. Schlueter, Douglas Christopher Wilson.