Skip to content

Commit 8c981e0

Browse files
v1rtlclaude
andauthored
refactor(accepts): inline negotiator dependency (#479)
* refactor(accepts): inline negotiator dependency - Add packages/accepts/src/negotiator.ts with full TypeScript implementation - Remove negotiator and @types/negotiator dependencies - Add comprehensive test suite (44 tests) for negotiator functionality - Reduces external dependencies by 2 packages Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(accepts): use # for private fields Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(accepts): remove unused BaseSpec interface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(accepts): deduplicate compare functions Replace 4 identical compareXxxSpecs functions with single compareByQI. 525 → 513 lines. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(accepts): modernize negotiator.ts with ES2022+ features - Use flatMap instead of for loops with push for parse functions - Use find for q-value extraction instead of for loops - Use reduce for priority calculation functions - Use template literals for string concatenation - Use regex match for quoteCount function - Use ternary expressions where cleaner Reduces file from 513 to 430 lines (~16% reduction) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style(accepts): apply Biome formatting Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: add changeset for inlined negotiator Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(accepts): fix split functions and improve test coverage - Fix splitMediaTypes to truncate array after merging quoted sections - Fix splitParameters similarly - Add test for mismatched media type parameters - Add test for comma inside quoted parameter - Add test for semicolon inside quoted parameter Achieves 100% line coverage for negotiator.ts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(accepts): add more tests for full coverage - Add array header tests for charsets, encodings, languages - Add malformed input tests for charsets and languages - Add invalid provided format tests for languages and mediaTypes - Add wildcard parameter value test for mediaTypes - Add parameter without value test - Add minQuality test for implicit identity encoding Now at 57 tests with 100% line coverage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c31446a commit 8c981e0

6 files changed

Lines changed: 765 additions & 24 deletions

File tree

.changeset/inline-negotiator.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tinyhttp/accepts": minor
3+
---
4+
5+
Inline negotiator package to reduce external dependencies. The `negotiator` and `@types/negotiator` packages are no longer required as dependencies.

packages/accepts/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@
2222
"files": [
2323
"dist"
2424
],
25-
"devDependencies": {
26-
"@types/negotiator": "^0.6.4"
27-
},
2825
"dependencies": {
29-
"mime": "4.1.0",
30-
"negotiator": "^1.0.0"
26+
"mime": "4.1.0"
3127
},
3228
"scripts": {
3329
"build": "tsc"

packages/accepts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IncomingMessage as I, IncomingHttpHeaders } from 'node:http'
22
import mime from 'mime'
3-
import Negotiator from 'negotiator'
3+
import { Negotiator } from './negotiator.js'
44

55
const extToMime = (type: string) => (type.indexOf('/') === -1 ? mime.getType(type) : type)
66

0 commit comments

Comments
 (0)