This package has been deprecated

Author message:

use @chubbyts/chubbyts-negotiation instead

@chubbyjs/chubbyjs-negotiation

1.0.0 • Public • Published

chubbyjs-negotiation

CI Coverage Status Infection MSI npm-version

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

A simple negotiation library.

Requirements

Installation

Through NPM as @chubbyjs/chubbyjs-negotiation.

npm i @chubbyjs/chubbyjs-negotiation@1.0.0

Usage

AcceptLanguageNegotiator

import AcceptLanguageNegotiator from '@chubbyjs/chubbyjs-negotiation/dist/AcceptLanguageNegotiator';

const request = ...withHeader('Accept-Language', 'de,en;q=0.3,en-US;q=0.7');

const negotiator = new AcceptLanguageNegotiator(['en', 'de']);
const value = negotiator.negotiate(request); // NegotiatedValue
value.getValue(); // de
value.getAttributes(); // new Map([['q' => '1.0']])

AcceptNegotiator

import AcceptNegotiator from '@chubbyjs/chubbyjs-negotiation/dist/AcceptNegotiator';

const request = ...withHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q =0.8');

const negotiator = new AcceptNegotiator(['application/json', 'application/xml', 'application/x-yaml']);
const value = negotiator.negotiate(request); // NegotiatedValue
value.getValue(); // application/xml
value.getAttributes(); // new Map([['q' => '0.9']])

ContentTypeNegotiator

import ContentTypeNegotiator from '@chubbyjs/chubbyjs-negotiation/dist/ContentTypeNegotiator';

const request = ...withHeader('Content-Type', 'application/xml; charset=UTF-8');

const negotiator = new ContentTypeNegotiator(['application/json', 'application/xml', 'application/x-yaml']);
const value = negotiator.negotiate($request); // NegotiatedValue
value->getValue(); // application/xml
value->getAttributes(); // new Map([['charset' => 'UTF-8']])

Copyright

Dominik Zogg 2021

Package Sidebar

Install

npm i @chubbyjs/chubbyjs-negotiation

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

19.7 kB

Total Files

21

Last publish

Collaborators

  • dominikzogg