https://github.com/nlibjs/negotiate
Utilities for content negotiation described in Section 5.3 of RFC 7231.
https://github.com/nlibjs/negotiate
Last synced: 5 months ago
JSON representation
Utilities for content negotiation described in Section 5.3 of RFC 7231.
- Host: GitHub
- URL: https://github.com/nlibjs/negotiate
- Owner: nlibjs
- License: apache-2.0
- Created: 2022-08-07T00:09:12.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-08-03T17:59:47.000Z (11 months ago)
- Last Synced: 2025-08-03T19:35:35.594Z (11 months ago)
- Language: TypeScript
- Homepage:
- Size: 819 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# @nlib/negotiate
[](https://github.com/nlibjs/negotiate/actions/workflows/test.yml)
[](https://codecov.io/gh/nlibjs/negotiate)
Utilities for content negotiation described in [Section 5.3 of RFC 7231].
[Section 5.3 of RFC 7231]: https://www.rfc-editor.org/rfc/rfc7231.html#section-5.3
## negotiate
```typescript
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
```typescript
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
```typescript
parseNegotiationItem('text/html;charset=utf-8;foo=1');
// → {value: 'text/html', parameters: {charset: 'utf-8', foo: '1'}}
```