Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

chubbyjs-legacy/chubbyjs-negotiation

Repository files navigation

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/[email protected]

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

About

A simple negotiation library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published