Socket
Socket
Sign inDemoInstall

@types/accepts

Package Overview
Dependencies
1
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/accepts

TypeScript definitions for accepts


Version published
Weekly downloads
2.2M
decreased by-1.7%
Maintainers
1
Install size
696 kB
Created
Weekly downloads
 

Package description

What is @types/accepts?

The @types/accepts npm package provides TypeScript type definitions for the 'accepts' npm package, which is a utility for content negotiation in HTTP requests. It allows developers to use TypeScript to ensure type safety when working with HTTP Accept headers for determining the preferred content types, encodings, charsets, and languages from HTTP requests.

What are @types/accepts's main functionalities?

Content Type Negotiation

This feature allows the server to negotiate and determine the most appropriate content type to respond with, based on the client's Accept header. The code sample demonstrates how to use the 'accepts' library to select between 'json' and 'html' formats.

import accepts from 'accepts';
import http from 'http';

http.createServer((req, res) => {
  const accept = accepts(req);
  const preferredType = accept.type(['json', 'html']);
  res.setHeader('Content-Type', preferredType);
  res.end(`Content type set to ${preferredType}`);
}).listen(3000);

Encoding Negotiation

This feature enables the server to select the best encoding method for the response based on the client's Accept-Encoding header. The code sample shows how to determine whether to use 'gzip' or 'deflate' encoding.

import accepts from 'accepts';
import http from 'http';

http.createServer((req, res) => {
  const accept = accepts(req);
  const preferredEncoding = accept.encoding(['gzip', 'deflate']);
  res.setHeader('Content-Encoding', preferredEncoding);
  res.end(`Content encoding set to ${preferredEncoding}`);
}).listen(3000);

Language Negotiation

This feature helps in determining the preferred language for the response content based on the client's Accept-Language header. The code sample illustrates how to choose between English ('en') and Spanish ('es').

import accepts from 'accepts';
import http from 'http';

http.createServer((req, res) => {
  const accept = accepts(req);
  const preferredLanguage = accept.language(['en', 'es']);
  res.setHeader('Content-Language', preferredLanguage);
  res.end(`Content language set to ${preferredLanguage}`);
}).listen(3000);

Other packages similar to @types/accepts

Readme

Source

Installation

npm install --save @types/accepts

Summary

This package contains type definitions for accepts (https://github.com/jshttp/accepts).

Details

Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/accepts

Additional Details

  • Last updated: Tue, 13 Feb 2018 02:54:18 GMT
  • Dependencies: http, node
  • Global values: none

Credits

These definitions were written by Stefan Reichel https://github.com/bomret, Brice BERNARD https://github.com/brikou.

FAQs

Last updated on 13 Feb 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc