@d1g1tal/media-type 5.0.2 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +393 -0
- package/README.md +150 -6
- package/package.json +84 -77
- package/dist/media-type.js +0 -299
- package/dist/media-type.min.js +0 -3
- package/dist/media-type.min.js.map +0 -7
- package/src/media-type-parameters.js +0 -111
- package/src/media-type-parser.js +0 -120
- package/src/media-type.js +0 -101
- package/src/utils.js +0 -3
- /package/{LICENSE.txt → LICENSE} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
## [6.0.1](https://github.com/D1g1talEntr0py/media-type/compare/v6.0.0...v6.0.1) (2026-03-01)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **ci:** add workflow_dispatch trigger, correct tarball glob, and add type-check script (a46c2c19baf6c49b3b4e57da3e36de08a6df9e1f)
|
|
6
|
+
|
|
7
|
+
### Code Refactoring
|
|
8
|
+
|
|
9
|
+
* **parser:** simplify component collection API (681e8f275b46cc39a6f146f1bcdddd85a277136a)
|
|
10
|
+
Replaces the options-object-based filterComponent method with a
|
|
11
|
+
straighter collect function returning a tuple, eliminating unnecessary
|
|
12
|
+
parameter grouping and making call sites easier to read.
|
|
13
|
+
|
|
14
|
+
Switches the whitespace character lookup from an array (O(n) includes)
|
|
15
|
+
to a Set (O(1) has) for a small but consistent performance gain.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Documentation
|
|
19
|
+
|
|
20
|
+
* update README badges and fix minor formatting (51cf9457fc604cccde032c060ecb86bf876a9713)
|
|
21
|
+
Replaces static badge URLs with dynamic ones that show live npm download
|
|
22
|
+
counts and the new CI/Codecov status badges, giving visitors an
|
|
23
|
+
immediate signal of project health.
|
|
24
|
+
|
|
25
|
+
Fixes trailing-whitespace and import-block formatting issues.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Miscellaneous Chores
|
|
29
|
+
|
|
30
|
+
* **release:** 5.1.0 [skip ci] (f3c6cbffe6ed87a59a5c7b321fc69d269ac61d28)
|
|
31
|
+
## [5.1.0](https://github.com/D1g1talEntr0py/media-type/compare/v5.0.0...v5.1.0) (2026-03-01)
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* convert to TypeScript (06901a60aa3d0643815e5f3c53d934f2dae0b361)
|
|
36
|
+
|
|
37
|
+
### Code Refactoring
|
|
38
|
+
|
|
39
|
+
* **parser:** simplify component collection API (681e8f275b46cc39a6f146f1bcdddd85a277136a)
|
|
40
|
+
Replaces the options-object-based filterComponent method with a
|
|
41
|
+
straighter collect function returning a tuple, eliminating unnecessary
|
|
42
|
+
parameter grouping and making call sites easier to read.
|
|
43
|
+
|
|
44
|
+
Switches the whitespace character lookup from an array (O(n) includes)
|
|
45
|
+
to a Set (O(1) has) for a small but consistent performance gain.
|
|
46
|
+
|
|
47
|
+
### Documentation
|
|
48
|
+
|
|
49
|
+
* update README badges and fix minor formatting (51cf9457fc604cccde032c060ecb86bf876a9713)
|
|
50
|
+
Replaces static badge URLs with dynamic ones that show live npm download
|
|
51
|
+
counts and the new CI/Codecov status badges, giving visitors an
|
|
52
|
+
immediate signal of project health.
|
|
53
|
+
|
|
54
|
+
Fixes trailing-whitespace and import-block formatting issues.
|
|
55
|
+
|
|
56
|
+
### Miscellaneous Chores
|
|
57
|
+
|
|
58
|
+
* upgrade dev dependencies to latest versions (6b54d8b1cddf7dbc824dba54fd5933570b66a262)
|
|
59
|
+
Bumps eslint to v10, typescript-eslint to 8.56, vitest/coverage-v8/ui
|
|
60
|
+
to 4.0.18, @types/node to 25, @types/web to 0.0.338, and several
|
|
61
|
+
transitive deps (esbuild, rollup, vite, acorn, ajv, etc.).
|
|
62
|
+
|
|
63
|
+
Adds @d1g1tal/tsbuild as the project build tool, replacing the previous
|
|
64
|
+
build setup, and introduces a type-check script. Removes the duplicate
|
|
65
|
+
coverage script alias. Sets the minimum Node.js engine to >=20.16.0.
|
|
66
|
+
|
|
67
|
+
Updates .gitignore to track .tsbuild/ output directory.
|
|
68
|
+
|
|
69
|
+
### Build System
|
|
70
|
+
|
|
71
|
+
* add semantic-release config and release docs (1cdaab0d9db81c363cf1d81e8ae36e758b2b7c57)
|
|
72
|
+
Adds a .releaserc.json that configures semantic-release with the
|
|
73
|
+
conventionalcommits preset, custom release rules (refactor triggers a
|
|
74
|
+
patch bump), grouped changelog sections, npm pack + publish with
|
|
75
|
+
provenance, and a git commit of CHANGELOG.md and package.json after
|
|
76
|
+
each release.
|
|
77
|
+
|
|
78
|
+
Adds a release-process.md guide explaining how to author commits,
|
|
79
|
+
open PRs, merge to main, and verify the automated release, including
|
|
80
|
+
a dry-run section and a troubleshooting FAQ.
|
|
81
|
+
|
|
82
|
+
### Continuous Integration
|
|
83
|
+
|
|
84
|
+
* add GitHub Actions workflows for CI and release (4ad266f7984742e7c5dd722340dc3c0786e4c7c9)
|
|
85
|
+
Adds a CI workflow that runs lint, type-check, tests with coverage, and
|
|
86
|
+
build across Node.js 20, 22, and 24 on every push and pull request to
|
|
87
|
+
main. Coverage is uploaded to Codecov from the Node 24 run only.
|
|
88
|
+
|
|
89
|
+
Adds a release workflow powered by semantic-release that triggers on
|
|
90
|
+
merges to main and fully automates versioning, changelog generation, npm
|
|
91
|
+
publish with provenance, and GitHub Release creation.
|
|
92
|
+
|
|
93
|
+
Adds a commit-msg git hook that enforces Conventional Commits format so
|
|
94
|
+
that semantic-release can reliably determine version bumps.
|
|
95
|
+
|
|
96
|
+
* add packageManager field for pnpm/action-setup (ee441628159346a66013bb429bf30e583d687b03)
|
|
97
|
+
* trigger actions (836151dd5d4e73e3bf51f2a6d5b11f462eef25a8)
|
|
98
|
+
* trigger actions (c415c4a08169fa103acbaaa9a1268485df6eb4e0)
|
|
99
|
+
* trigger actions (fc350c91e7e2546604361aade7f0f55530095b38)
|
|
100
|
+
|
|
101
|
+
* **release:** 5.1.1 [skip ci] (f4d1336e1031a2d42ff9e2f091019ae0bb90d5f5)
|
|
102
|
+
## [5.1.1](https://github.com/D1g1talEntr0py/media-type/compare/v5.1.0...v5.1.1) (2026-03-01)
|
|
103
|
+
|
|
104
|
+
### Bug Fixes
|
|
105
|
+
|
|
106
|
+
* **ci:** add workflow_dispatch trigger, correct tarball glob, and add type-check script (a46c2c19baf6c49b3b4e57da3e36de08a6df9e1f)
|
|
107
|
+
|
|
108
|
+
### Tests
|
|
109
|
+
|
|
110
|
+
* removed web-platform-tests from .gitignore (db2fbdd787928e9b5ac2661bd4a738221f084280)
|
|
111
|
+
|
|
112
|
+
### Continuous Integration
|
|
113
|
+
|
|
114
|
+
* added missing test data (12d03ca176a8c4407610774e599325df7790e0bc)
|
|
115
|
+
|
|
116
|
+
* restore correct version and revert bad 5.1.1 changelog entry (c47f3bf32826152f6f6b363e4ed63a9d61ea61dd)
|
|
117
|
+
* upgrade dev dependencies to latest versions (6b54d8b1cddf7dbc824dba54fd5933570b66a262)
|
|
118
|
+
Bumps eslint to v10, typescript-eslint to 8.56, vitest/coverage-v8/ui
|
|
119
|
+
to 4.0.18, @types/node to 25, @types/web to 0.0.338, and several
|
|
120
|
+
transitive deps (esbuild, rollup, vite, acorn, ajv, etc.).
|
|
121
|
+
|
|
122
|
+
Adds @d1g1tal/tsbuild as the project build tool, replacing the previous
|
|
123
|
+
build setup, and introduces a type-check script. Removes the duplicate
|
|
124
|
+
coverage script alias. Sets the minimum Node.js engine to >=20.16.0.
|
|
125
|
+
|
|
126
|
+
Updates .gitignore to track .tsbuild/ output directory.
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
### Tests
|
|
130
|
+
|
|
131
|
+
* removed web-platform-tests from .gitignore (db2fbdd787928e9b5ac2661bd4a738221f084280)
|
|
132
|
+
|
|
133
|
+
### Build System
|
|
134
|
+
|
|
135
|
+
* add semantic-release config and release docs (1cdaab0d9db81c363cf1d81e8ae36e758b2b7c57)
|
|
136
|
+
Adds a .releaserc.json that configures semantic-release with the
|
|
137
|
+
conventionalcommits preset, custom release rules (refactor triggers a
|
|
138
|
+
patch bump), grouped changelog sections, npm pack + publish with
|
|
139
|
+
provenance, and a git commit of CHANGELOG.md and package.json after
|
|
140
|
+
each release.
|
|
141
|
+
|
|
142
|
+
Adds a release-process.md guide explaining how to author commits,
|
|
143
|
+
open PRs, merge to main, and verify the automated release, including
|
|
144
|
+
a dry-run section and a troubleshooting FAQ.
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
### Continuous Integration
|
|
148
|
+
|
|
149
|
+
* add GitHub Actions workflows for CI and release (4ad266f7984742e7c5dd722340dc3c0786e4c7c9)
|
|
150
|
+
Adds a CI workflow that runs lint, type-check, tests with coverage, and
|
|
151
|
+
build across Node.js 20, 22, and 24 on every push and pull request to
|
|
152
|
+
main. Coverage is uploaded to Codecov from the Node 24 run only.
|
|
153
|
+
|
|
154
|
+
Adds a release workflow powered by semantic-release that triggers on
|
|
155
|
+
merges to main and fully automates versioning, changelog generation, npm
|
|
156
|
+
publish with provenance, and GitHub Release creation.
|
|
157
|
+
|
|
158
|
+
Adds a commit-msg git hook that enforces Conventional Commits format so
|
|
159
|
+
that semantic-release can reliably determine version bumps.
|
|
160
|
+
|
|
161
|
+
* add packageManager field for pnpm/action-setup (ee441628159346a66013bb429bf30e583d687b03)
|
|
162
|
+
* added missing test data (12d03ca176a8c4407610774e599325df7790e0bc)
|
|
163
|
+
* trigger actions (836151dd5d4e73e3bf51f2a6d5b11f462eef25a8)
|
|
164
|
+
* trigger actions (c415c4a08169fa103acbaaa9a1268485df6eb4e0)
|
|
165
|
+
* trigger actions (fc350c91e7e2546604361aade7f0f55530095b38)
|
|
166
|
+
|
|
167
|
+
## [5.1.0](https://github.com/D1g1talEntr0py/media-type/compare/v5.0.0...v5.1.0) (2026-03-01)
|
|
168
|
+
|
|
169
|
+
### Features
|
|
170
|
+
|
|
171
|
+
* convert to TypeScript (06901a60aa3d0643815e5f3c53d934f2dae0b361)
|
|
172
|
+
|
|
173
|
+
### Code Refactoring
|
|
174
|
+
|
|
175
|
+
* **parser:** simplify component collection API (681e8f275b46cc39a6f146f1bcdddd85a277136a)
|
|
176
|
+
Replaces the options-object-based filterComponent method with a
|
|
177
|
+
straighter collect function returning a tuple, eliminating unnecessary
|
|
178
|
+
parameter grouping and making call sites easier to read.
|
|
179
|
+
|
|
180
|
+
Switches the whitespace character lookup from an array (O(n) includes)
|
|
181
|
+
to a Set (O(1) has) for a small but consistent performance gain.
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
### Documentation
|
|
185
|
+
|
|
186
|
+
* update README badges and fix minor formatting (51cf9457fc604cccde032c060ecb86bf876a9713)
|
|
187
|
+
Replaces static badge URLs with dynamic ones that show live npm download
|
|
188
|
+
counts and the new CI/Codecov status badges, giving visitors an
|
|
189
|
+
immediate signal of project health.
|
|
190
|
+
|
|
191
|
+
Fixes trailing-whitespace and import-block formatting issues.
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
### Miscellaneous Chores
|
|
195
|
+
|
|
196
|
+
* upgrade dev dependencies to latest versions (6b54d8b1cddf7dbc824dba54fd5933570b66a262)
|
|
197
|
+
Bumps eslint to v10, typescript-eslint to 8.56, vitest/coverage-v8/ui
|
|
198
|
+
to 4.0.18, @types/node to 25, @types/web to 0.0.338, and several
|
|
199
|
+
transitive deps (esbuild, rollup, vite, acorn, ajv, etc.).
|
|
200
|
+
|
|
201
|
+
Adds @d1g1tal/tsbuild as the project build tool, replacing the previous
|
|
202
|
+
build setup, and introduces a type-check script. Removes the duplicate
|
|
203
|
+
coverage script alias. Sets the minimum Node.js engine to >=20.16.0.
|
|
204
|
+
|
|
205
|
+
Updates .gitignore to track .tsbuild/ output directory.
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
### Build System
|
|
209
|
+
|
|
210
|
+
* add semantic-release config and release docs (1cdaab0d9db81c363cf1d81e8ae36e758b2b7c57)
|
|
211
|
+
Adds a .releaserc.json that configures semantic-release with the
|
|
212
|
+
conventionalcommits preset, custom release rules (refactor triggers a
|
|
213
|
+
patch bump), grouped changelog sections, npm pack + publish with
|
|
214
|
+
provenance, and a git commit of CHANGELOG.md and package.json after
|
|
215
|
+
each release.
|
|
216
|
+
|
|
217
|
+
Adds a release-process.md guide explaining how to author commits,
|
|
218
|
+
open PRs, merge to main, and verify the automated release, including
|
|
219
|
+
a dry-run section and a troubleshooting FAQ.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
### Continuous Integration
|
|
223
|
+
|
|
224
|
+
* add GitHub Actions workflows for CI and release (4ad266f7984742e7c5dd722340dc3c0786e4c7c9)
|
|
225
|
+
Adds a CI workflow that runs lint, type-check, tests with coverage, and
|
|
226
|
+
build across Node.js 20, 22, and 24 on every push and pull request to
|
|
227
|
+
main. Coverage is uploaded to Codecov from the Node 24 run only.
|
|
228
|
+
|
|
229
|
+
Adds a release workflow powered by semantic-release that triggers on
|
|
230
|
+
merges to main and fully automates versioning, changelog generation, npm
|
|
231
|
+
publish with provenance, and GitHub Release creation.
|
|
232
|
+
|
|
233
|
+
Adds a commit-msg git hook that enforces Conventional Commits format so
|
|
234
|
+
that semantic-release can reliably determine version bumps.
|
|
235
|
+
|
|
236
|
+
* add packageManager field for pnpm/action-setup (ee441628159346a66013bb429bf30e583d687b03)
|
|
237
|
+
* trigger actions (836151dd5d4e73e3bf51f2a6d5b11f462eef25a8)
|
|
238
|
+
* trigger actions (c415c4a08169fa103acbaaa9a1268485df6eb4e0)
|
|
239
|
+
* trigger actions (fc350c91e7e2546604361aade7f0f55530095b38)
|
|
240
|
+
|
|
241
|
+
# Changelog
|
|
242
|
+
|
|
243
|
+
All notable changes to this project will be documented in this file.
|
|
244
|
+
|
|
245
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
246
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
247
|
+
|
|
248
|
+
## [6.0.0] - 2024-06-15
|
|
249
|
+
|
|
250
|
+
### Changed
|
|
251
|
+
- **Complete TypeScript conversion**: Converted all source and test files from JavaScript to TypeScript
|
|
252
|
+
- **Test framework**: Migrated from Jest to Vitest with coverage support
|
|
253
|
+
- Updated ESLint to modern flat config format
|
|
254
|
+
- Enhanced README with badges, features, and migration guide
|
|
255
|
+
- Updated package.json with proper TypeScript exports
|
|
256
|
+
|
|
257
|
+
### Added
|
|
258
|
+
- Native TypeScript type definitions with strict compiler options
|
|
259
|
+
- TypeScript interfaces: `MediaTypeComponent`, `ParsedMediaType`
|
|
260
|
+
- tsconfig.json with isolated declarations
|
|
261
|
+
- Vitest configuration with UI and coverage (`@vitest/coverage-v8`, `@vitest/ui`)
|
|
262
|
+
- `@types/node` dev dependency
|
|
263
|
+
- Comprehensive CHANGELOG
|
|
264
|
+
- Automated version script for releases
|
|
265
|
+
|
|
266
|
+
## [5.0.2] - 2023-XX-XX
|
|
267
|
+
|
|
268
|
+
### Fixed
|
|
269
|
+
- Maintenance release with dependency updates
|
|
270
|
+
|
|
271
|
+
## [5.0.0] - 2023-11-11
|
|
272
|
+
|
|
273
|
+
### Changed
|
|
274
|
+
- Switched to pnpm for package management
|
|
275
|
+
- Switched license from MIT to ISC
|
|
276
|
+
- Refactored `MediaTypeParameters` to extend Map directly (instead of wrapping)
|
|
277
|
+
- Refactored parser to use class with static methods
|
|
278
|
+
- Moved serializer functionality into `MediaType.toString()`
|
|
279
|
+
- Changed package manager from npm/yarn to pnpm
|
|
280
|
+
- Removed `esbuild-library` dependency in favor of simpler TypeScript compilation
|
|
281
|
+
|
|
282
|
+
#### API Changes - BREAKING CHANGES
|
|
283
|
+
|
|
284
|
+
##### Renamed Classes
|
|
285
|
+
- **`MIMEType` → `MediaType`**: Main class renamed to reflect WHATWG terminology
|
|
286
|
+
- **`MIMETypeParameters` → `MediaTypeParameters`**: Parameters class renamed accordingly
|
|
287
|
+
|
|
288
|
+
##### Removed Methods
|
|
289
|
+
The following methods have been **removed** from the `MediaType` class:
|
|
290
|
+
- `isHTML()` - Removed (was marked as speculative in original package)
|
|
291
|
+
- `isXML()` - Removed (was marked as speculative in original package)
|
|
292
|
+
- `isJavaScript({ prohibitParameters })` - Removed (was marked as speculative in original package)
|
|
293
|
+
|
|
294
|
+
**Migration Guide**: If you were using these methods, you'll need to implement your own checks:
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
// Old (v4.x with whatwg-mimetype)
|
|
298
|
+
if (mimeType.isHTML()) { /* ... */ }
|
|
299
|
+
|
|
300
|
+
// New (v5.x with @d1g1tal/media-type)
|
|
301
|
+
if (mediaType.essence === 'text/html') { /* ... */ }
|
|
302
|
+
// or for more comprehensive HTML MIME type checking:
|
|
303
|
+
const htmlTypes = ['text/html', 'application/xhtml+xml'];
|
|
304
|
+
if (htmlTypes.includes(mediaType.essence)) { /* ... */ }
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
##### New Methods
|
|
308
|
+
- **`matches(mediaType: MediaType | string): boolean`**: New method to check if media type matches a specified type
|
|
309
|
+
- Accepts either a `MediaType` instance or a string
|
|
310
|
+
- For strings: checks if the essence includes the string (e.g., `mediaType.matches('html')`)
|
|
311
|
+
- For `MediaType` instances: performs exact type/subtype comparison
|
|
312
|
+
|
|
313
|
+
##### Constructor Changes
|
|
314
|
+
- **Constructor signature change**: Now accepts optional second parameter for overriding parameters
|
|
315
|
+
```typescript
|
|
316
|
+
// New in v5.0
|
|
317
|
+
const mediaType = new MediaType('text/html;charset=iso-8859-1', { charset: 'utf-8' });
|
|
318
|
+
// Results in: text/html;charset=utf-8
|
|
319
|
+
```
|
|
320
|
+
- **Removed object-only constructor**: Can no longer pass just an object to constructor
|
|
321
|
+
- Old: `new MIMEType({ type: 'text', subtype: 'html' })` ❌
|
|
322
|
+
- New: Must pass string as first parameter ✅
|
|
323
|
+
|
|
324
|
+
##### Internal Architecture Changes
|
|
325
|
+
- **`MediaTypeParameters` now extends `Map`**: Previously wrapped a Map, now directly extends it
|
|
326
|
+
- Reduces file size and complexity
|
|
327
|
+
- All Map methods directly available
|
|
328
|
+
- Still maintains media type-specific validation (case-insensitive parameter names, HTTP token validation)
|
|
329
|
+
|
|
330
|
+
- **Parser refactored to class**: Module with exported functions converted to `MediaTypeParser` class with static methods
|
|
331
|
+
- **Serializer merged**: Separate serializer module removed, `serialize` functionality moved into `MediaType.toString()`
|
|
332
|
+
- **Utility optimizations**: Util functions moved directly into classes where used only once
|
|
333
|
+
|
|
334
|
+
#### Module System Changes
|
|
335
|
+
- Pure ES Modules (ESM) - no CommonJS support
|
|
336
|
+
- Updated exports structure in package.json
|
|
337
|
+
- Import extensions required: `.js` extensions must be used in TypeScript imports
|
|
338
|
+
|
|
339
|
+
#### Properties Made Private
|
|
340
|
+
- Internal `_type`, `_subtype`, and `_parameters` properties are now properly private
|
|
341
|
+
- Access only through public getters
|
|
342
|
+
- `type` and `subtype` are now read-only (getter-only)
|
|
343
|
+
|
|
344
|
+
#### Development Experience
|
|
345
|
+
- Added comprehensive ESLint configuration with TypeScript support
|
|
346
|
+
- Added `eslint-plugin-jsdoc` for JSDoc validation
|
|
347
|
+
- Improved test coverage with Vitest
|
|
348
|
+
- Added coverage reporting with `@vitest/coverage-v8`
|
|
349
|
+
- Web Platform Tests integration maintained and updated
|
|
350
|
+
|
|
351
|
+
#### License Change
|
|
352
|
+
- **License changed from MIT to ISC**
|
|
353
|
+
- Maintainer changed to Jason DiMeo
|
|
354
|
+
|
|
355
|
+
### Added
|
|
356
|
+
- `matches()` method for media type comparison
|
|
357
|
+
- Second constructor parameter for parameter overrides
|
|
358
|
+
- Full TypeScript type definitions
|
|
359
|
+
- Vitest UI support for interactive testing
|
|
360
|
+
|
|
361
|
+
### Changed
|
|
362
|
+
- Package name: `whatwg-mimetype` → `@d1g1tal/media-type`
|
|
363
|
+
- License: MIT → ISC
|
|
364
|
+
- Build system: esbuild-library → tsbuild
|
|
365
|
+
- Test framework: Jest → Vitest
|
|
366
|
+
- Package manager: npm/yarn → pnpm
|
|
367
|
+
- Module system: CommonJS → Pure ESM
|
|
368
|
+
|
|
369
|
+
### Removed
|
|
370
|
+
- `isHTML()` method
|
|
371
|
+
- `isXML()` method
|
|
372
|
+
- `isJavaScript()` method
|
|
373
|
+
- Object-only constructor signature
|
|
374
|
+
- CommonJS support
|
|
375
|
+
- Separate serializer module
|
|
376
|
+
- `esbuild-library` dependency
|
|
377
|
+
- `minipass-fetch` dev dependency (replaced with built-in fetch API)
|
|
378
|
+
- `rimraf` dev dependency (tsbuild handles cleaning)
|
|
379
|
+
|
|
380
|
+
## [4.x.x] - Previous versions
|
|
381
|
+
|
|
382
|
+
See the original [whatwg-mimetype](https://github.com/jsdom/whatwg-mimetype) repository for version 4.x.x and earlier history.
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## Original Package Information
|
|
387
|
+
|
|
388
|
+
This package is a fork of [`whatwg-mimetype`](https://github.com/jsdom/whatwg-mimetype) by Domenic Denicola and contributors. The original package was licensed under MIT. This fork has been substantially rewritten with breaking changes and is licensed under ISC.
|
|
389
|
+
|
|
390
|
+
**Original Author**: Domenic Denicola <d@domenic.me> (https://domenic.me/)
|
|
391
|
+
**Current Maintainer**: Jason DiMeo <jason.dimeo@gmail.com>
|
|
392
|
+
|
|
393
|
+
The original package contributors and their excellent work are acknowledged with gratitude.
|
package/README.md
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
# Parse, serialize, and manipulate media types
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@d1g1tal/media-type)
|
|
4
|
+
[](https://www.npmjs.com/package/@d1g1tal/media-type)
|
|
5
|
+
[](https://github.com/D1g1talEntr0py/media-type/actions/workflows/ci.yml)
|
|
6
|
+
[](https://codecov.io/gh/D1g1talEntr0py/media-type)
|
|
7
|
+
[](https://github.com/D1g1talEntr0py/media-type/blob/main/LICENSE)
|
|
8
|
+
[](https://nodejs.org)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
4
10
|
|
|
5
|
-
This
|
|
11
|
+
> **Note**: This is a TypeScript rewrite and fork of the original [`whatwg-mimetype`](https://github.com/jsdom/whatwg-mimetype) package. See [CHANGELOG.md](./CHANGELOG.md) for migration information.
|
|
12
|
+
|
|
13
|
+
This package will parse [MIME types](https://mimesniff.spec.whatwg.org/#understanding-mime-types) (also known as media types) into a structured format, which can then be manipulated and serialized according to the WHATWG MIME Sniffing Standard.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- ✅ **WHATWG Standard Compliant**: Implements the [WHATWG MIME Sniffing Standard](https://mimesniff.spec.whatwg.org/)
|
|
18
|
+
- ✅ **Full TypeScript Support**: Written in TypeScript with complete type definitions
|
|
19
|
+
- ✅ **Pure ES Modules**: Modern ESM-only package
|
|
20
|
+
- ✅ **Zero Dependencies**: No runtime dependencies
|
|
21
|
+
- ✅ **Extensive Testing**: Includes WHATWG web platform tests
|
|
22
|
+
- ✅ **Lightweight**: Minimal bundle size
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @d1g1tal/media-type
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pnpm add @d1g1tal/media-type
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
yarn add @d1g1tal/media-type
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
6
39
|
|
|
7
40
|
```js
|
|
8
|
-
import MediaType from '@d1g1tal/media-type';
|
|
41
|
+
import { MediaType } from '@d1g1tal/media-type';
|
|
9
42
|
|
|
10
43
|
const mediaType = new MediaType('Text/HTML;Charset="utf-8"');
|
|
11
44
|
|
|
@@ -28,6 +61,31 @@ Parsing is a fairly complex process; see [the specification](https://mimesniff.s
|
|
|
28
61
|
|
|
29
62
|
This package's algorithms conform to those of the WHATWG [MIME Sniffing Standard](https://mimesniff.spec.whatwg.org/), and is aligned up to commit [8e9a7dd](https://github.com/whatwg/mimesniff/commit/8e9a7dd90717c595a4e4d982cd216e4411d33736).
|
|
30
63
|
|
|
64
|
+
## Migration from whatwg-mimetype
|
|
65
|
+
|
|
66
|
+
If you're migrating from the original `whatwg-mimetype` package, please review the [CHANGELOG.md](./CHANGELOG.md) for breaking changes. Key changes include:
|
|
67
|
+
|
|
68
|
+
- **Class renamed**: `MIMEType` → `MediaType`
|
|
69
|
+
- **Removed methods**: `isHTML()`, `isXML()`, `isJavaScript()` - implement your own checks using the `essence` property
|
|
70
|
+
- **New method**: `matches(mediaType)` for flexible type matching
|
|
71
|
+
- **Properties now read-only**: `type` and `subtype` can only be read via getters
|
|
72
|
+
- **Constructor change**: Optional second parameter to override parsed parameters
|
|
73
|
+
- **Pure ESM**: No CommonJS support
|
|
74
|
+
|
|
75
|
+
### Quick Migration Example
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
// Old (whatwg-mimetype v4.x)
|
|
79
|
+
import MIMEType from 'whatwg-mimetype';
|
|
80
|
+
const mimeType = new MIMEType('text/html');
|
|
81
|
+
if (mimeType.isHTML()) { /* ... */ }
|
|
82
|
+
|
|
83
|
+
// New (@d1g1tal/media-type v5.x)
|
|
84
|
+
import { MediaType } from '@d1g1tal/media-type';
|
|
85
|
+
const mediaType = new MediaType('text/html');
|
|
86
|
+
if (mediaType.essence === 'text/html' || mediaType.matches('html')) { /* ... */ }
|
|
87
|
+
```
|
|
88
|
+
|
|
31
89
|
## `MediaType` API
|
|
32
90
|
|
|
33
91
|
This package's main module's export is a class, `MediaType`. Its constructor takes a string which it will attempt to parse into a media type; if parsing fails, an `Error` will be thrown.
|
|
@@ -51,8 +109,10 @@ As an alternative to the constructor, you can use `MediaType.parse(string)`. The
|
|
|
51
109
|
|
|
52
110
|
### Methods
|
|
53
111
|
|
|
54
|
-
-
|
|
55
|
-
-
|
|
112
|
+
- **`toString()`**: Serializes the media type to a string
|
|
113
|
+
- **`matches(mediaType: MediaType | string)`**: Checks if the media type matches the specified type
|
|
114
|
+
- When passed a string: checks if the essence includes that string (e.g., `mediaType.matches('html')` returns `true` for `text/html`)
|
|
115
|
+
- When passed a `MediaType` instance: performs exact type/subtype comparison
|
|
56
116
|
|
|
57
117
|
## `MediaTypeParameters` API
|
|
58
118
|
|
|
@@ -83,4 +143,88 @@ console.assert(mediaType.toString() === 'x/x;a=b;c=d;e=F;q=X');
|
|
|
83
143
|
|
|
84
144
|
// Throws:
|
|
85
145
|
mediaType.parameters.set('@', 'x');
|
|
86
|
-
```
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Additional Exports
|
|
149
|
+
|
|
150
|
+
In addition to the main `MediaType` class, this package also exports:
|
|
151
|
+
|
|
152
|
+
- **`MediaTypeParameters`**: The parameters class (extends `Map<string, string>`)
|
|
153
|
+
- **`MediaTypeParser`**: Low-level parser with static methods
|
|
154
|
+
- **Type exports**: `MediaTypeComponent`, `ParsedMediaType` (TypeScript types)
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import {
|
|
158
|
+
MediaType,
|
|
159
|
+
MediaTypeParameters,
|
|
160
|
+
MediaTypeParser,
|
|
161
|
+
type MediaTypeComponent,
|
|
162
|
+
type ParsedMediaType
|
|
163
|
+
} from '@d1g1tal/media-type';
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Browser Support
|
|
167
|
+
|
|
168
|
+
This package uses modern ES features and is designed for:
|
|
169
|
+
- Modern browsers with ES6 module support
|
|
170
|
+
- Maintained Node.js versions (see `browserslist` in package.json)
|
|
171
|
+
|
|
172
|
+
## Development
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Install dependencies
|
|
176
|
+
pnpm install
|
|
177
|
+
|
|
178
|
+
# Run tests
|
|
179
|
+
pnpm test
|
|
180
|
+
|
|
181
|
+
# Run tests with coverage
|
|
182
|
+
pnpm test:coverage
|
|
183
|
+
|
|
184
|
+
# Run tests in watch mode
|
|
185
|
+
pnpm test:watch
|
|
186
|
+
|
|
187
|
+
# Run tests with UI
|
|
188
|
+
pnpm test:ui
|
|
189
|
+
|
|
190
|
+
# Build the package
|
|
191
|
+
pnpm build
|
|
192
|
+
|
|
193
|
+
# Lint
|
|
194
|
+
pnpm lint
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## About This Fork
|
|
198
|
+
|
|
199
|
+
This project is a fork and substantial rewrite of the excellent [`whatwg-mimetype`](https://github.com/jsdom/whatwg-mimetype) package by Domenic Denicola and contributors.
|
|
200
|
+
|
|
201
|
+
**Why fork?**
|
|
202
|
+
- Complete TypeScript rewrite for better type safety
|
|
203
|
+
- Modernize build tooling and dependencies
|
|
204
|
+
- Optimize bundle size and performance
|
|
205
|
+
- Maintain WHATWG standard compliance
|
|
206
|
+
|
|
207
|
+
**Original Author**: Domenic Denicola
|
|
208
|
+
**Current Maintainer**: Jason DiMeo
|
|
209
|
+
|
|
210
|
+
The original contributors' excellent work is acknowledged with gratitude. This fork maintains the same commitment to WHATWG standards compliance while providing a modern TypeScript-first experience.
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
ISC License - see [LICENSE](./LICENSE) file for details.
|
|
215
|
+
|
|
216
|
+
The original `whatwg-mimetype` package was licensed under MIT.
|
|
217
|
+
|
|
218
|
+
## Contributing
|
|
219
|
+
|
|
220
|
+
Contributions are welcome! Please ensure:
|
|
221
|
+
- All tests pass (`pnpm test`)
|
|
222
|
+
- Code follows the ESLint configuration
|
|
223
|
+
- TypeScript types are properly defined
|
|
224
|
+
- Changes are documented in the CHANGELOG
|
|
225
|
+
|
|
226
|
+
## Resources
|
|
227
|
+
|
|
228
|
+
- [WHATWG MIME Sniffing Standard](https://mimesniff.spec.whatwg.org/)
|
|
229
|
+
- [Original whatwg-mimetype package](https://github.com/jsdom/whatwg-mimetype)
|
|
230
|
+
- [Issue Tracker](https://github.com/D1g1talEntr0py/media-type/issues)
|