0.1.4 • Published 1 year ago

@nlib/negotiate v0.1.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

@nlib/negotiate

.github/workflows/test.yml codecov

Utilities for content negotiation described in Section 5.3 of RFC 7231.

negotiate

const supported = ['text/html', 'image/webp'];
const accept = 'text/html,image/avif,image/webp,image/apng,*/*;q=0.8';
negotiate(supported, accept); // → 'text/html'
negotiate([], accept); // → null

parseAcceptStatements

const generator = parseAcceptStatements('v1,v2;q=0.9,v3;q=0.8')
generator.next().value; // → {value: 'v1', q: 1}
generator.next().value; // → {value: 'v2', q: 0.9}
generator.next().value; // → {value: 'v3', q: 0.8}
generator.next(); // → {value: undefined, done: true}

parseNegotiationItem

parseNegotiationItem('text/html;charset=utf-8;foo=1')
// → {value: 'text/html', parameters: {charset: 'utf-8', foo: '1'}}
0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago