@d1g1tal/media-type 5.0.2 → 6.0.0

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.
@@ -1,20 +1,14 @@
1
- // node_modules/.pnpm/@d1g1tal+chrysalis@2.4.0/node_modules/@d1g1tal/chrysalis/src/esm/object-type.js
2
- var { toString } = Object.prototype;
3
- var _type = (object) => object?.constructor ?? globalThis[toString.call(object).slice(8, -1)] ?? object;
4
- var object_type_default = _type;
5
-
6
- // src/utils.js
1
+ // src/utils.ts
7
2
  var httpTokenCodePoints = /^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u;
8
- var utils_default = httpTokenCodePoints;
9
3
 
10
- // src/media-type-parameters.js
4
+ // src/media-type-parameters.ts
11
5
  var matcher = /(["\\])/ug;
12
6
  var httpQuotedStringTokenCodePoints = /^[\t\u0020-\u007E\u0080-\u00FF]*$/u;
13
7
  var MediaTypeParameters = class _MediaTypeParameters extends Map {
14
8
  /**
15
9
  * Create a new MediaTypeParameters instance.
16
10
  *
17
- * @param {Array<[string, string]>} entries An array of [name, value] tuples.
11
+ * @param entries An array of [ name, value ] tuples.
18
12
  */
19
13
  constructor(entries = []) {
20
14
  super(entries);
@@ -22,19 +16,18 @@ var MediaTypeParameters = class _MediaTypeParameters extends Map {
22
16
  /**
23
17
  * Indicates whether the supplied name and value are valid media type parameters.
24
18
  *
25
- * @static
26
- * @param {string} name The name of the media type parameter to validate.
27
- * @param {string} value The media type parameter value to validate.
28
- * @returns {boolean} true if the media type parameter is valid, false otherwise.
19
+ * @param name The name of the media type parameter to validate.
20
+ * @param value The media type parameter value to validate.
21
+ * @returns true if the media type parameter is valid, false otherwise.
29
22
  */
30
23
  static isValid(name, value) {
31
- return utils_default.test(name) && httpQuotedStringTokenCodePoints.test(value);
24
+ return httpTokenCodePoints.test(name) && httpQuotedStringTokenCodePoints.test(value);
32
25
  }
33
26
  /**
34
27
  * Gets the media type parameter value for the supplied name.
35
28
  *
36
- * @param {string} name The name of the media type parameter to retrieve.
37
- * @returns {string} The media type parameter value.
29
+ * @param name The name of the media type parameter to retrieve.
30
+ * @returns The media type parameter value.
38
31
  */
39
32
  get(name) {
40
33
  return super.get(name.toLowerCase());
@@ -42,8 +35,8 @@ var MediaTypeParameters = class _MediaTypeParameters extends Map {
42
35
  /**
43
36
  * Indicates whether the media type parameter with the specified name exists or not.
44
37
  *
45
- * @param {string} name The name of the media type parameter to check.
46
- * @returns {boolean} true if the media type parameter exists, false otherwise.
38
+ * @param name The name of the media type parameter to check.
39
+ * @returns true if the media type parameter exists, false otherwise.
47
40
  */
48
41
  has(name) {
49
42
  return super.has(name.toLowerCase());
@@ -52,9 +45,9 @@ var MediaTypeParameters = class _MediaTypeParameters extends Map {
52
45
  * Adds a new media type parameter using the specified name and value to the MediaTypeParameters.
53
46
  * If an parameter with the same name already exists, the parameter will be updated.
54
47
  *
55
- * @param {string} name The name of the media type parameter to set.
56
- * @param {string} value The media type parameter value.
57
- * @returns {MediaTypeParameters} This instance.
48
+ * @param name The name of the media type parameter to set.
49
+ * @param value The media type parameter value.
50
+ * @returns This instance.
58
51
  */
59
52
  set(name, value) {
60
53
  if (!_MediaTypeParameters.isValid(name, value)) {
@@ -66,8 +59,8 @@ var MediaTypeParameters = class _MediaTypeParameters extends Map {
66
59
  /**
67
60
  * Removes the media type parameter using the specified name.
68
61
  *
69
- * @param {string} name The name of the media type parameter to delete.
70
- * @returns {boolean} true if the parameter existed and has been removed, or false if the parameter does not exist.
62
+ * @param name The name of the media type parameter to delete.
63
+ * @returns true if the parameter existed and has been removed, or false if the parameter does not exist.
71
64
  */
72
65
  delete(name) {
73
66
  return super.delete(name.toLowerCase());
@@ -75,90 +68,89 @@ var MediaTypeParameters = class _MediaTypeParameters extends Map {
75
68
  /**
76
69
  * Returns a string representation of the media type parameters.
77
70
  *
78
- * @override
79
- * @returns {string} The string representation of the media type parameters.
71
+ * @returns The string representation of the media type parameters.
80
72
  */
81
73
  toString() {
82
- return Array.from(this).map(([name, value]) => `;${name}=${!value || !utils_default.test(value) ? `"${value.replace(matcher, "\\$1")}"` : value}`).join("");
74
+ return Array.from(this).map(([name, value]) => `;${name}=${!value || !httpTokenCodePoints.test(value) ? `"${value.replace(matcher, "\\$1")}"` : value}`).join("");
83
75
  }
84
76
  /**
85
77
  * Returns the name of this class.
86
78
  *
87
- * @override
88
- * @returns {string} The name of this class.
79
+ * @returns The name of this class.
89
80
  */
90
- [Symbol.toStringTag]() {
81
+ get [Symbol.toStringTag]() {
91
82
  return "MediaTypeParameters";
92
83
  }
93
84
  };
94
85
 
95
- // src/media-type-parser.js
86
+ // src/media-type-parser.ts
96
87
  var whitespaceCharacters = [" ", " ", "\n", "\r"];
97
88
  var trailingWhitespace = /[ \t\n\r]+$/u;
98
89
  var leadingAndTrailingWhitespace = /^[ \t\n\r]+|[ \t\n\r]+$/ug;
99
90
  var MediaTypeParser = class _MediaTypeParser {
100
91
  /**
101
92
  * Function to parse a media type.
102
- *
103
- * @static
104
- * @param {string} input The media type to parse
105
- * @returns {{ type: string, subtype: string, parameters: MediaTypeParameters }} An object populated with the parsed media type properties and any parameters.
93
+ * @param input The media type to parse
94
+ * @returns An object populated with the parsed media type properties and any parameters.
106
95
  */
107
96
  static parse(input) {
108
97
  input = input.replace(leadingAndTrailingWhitespace, "");
109
98
  const length = input.length, trim = true, lowerCase = false;
110
- let { position, result: type, subtype = "" } = _MediaTypeParser.#filterComponent({ input }, "/");
111
- if (!type.length || position >= length || !utils_default.test(type)) {
112
- throw new TypeError(_MediaTypeParser.#generateErrorMessage("type", type));
99
+ const { position: initialPosition, result: type } = _MediaTypeParser.filterComponent({ input }, "/");
100
+ let position = initialPosition;
101
+ if (!type.length || position >= length || !httpTokenCodePoints.test(type)) {
102
+ throw new TypeError(_MediaTypeParser.generateErrorMessage("type", type));
113
103
  }
114
- ({ position, result: subtype } = _MediaTypeParser.#filterComponent({ position: ++position, input, trim }, ";"));
115
- if (!subtype.length || !utils_default.test(subtype)) {
116
- throw new TypeError(_MediaTypeParser.#generateErrorMessage("subtype", subtype));
104
+ let subtype = "";
105
+ ({ position, result: subtype } = _MediaTypeParser.filterComponent({ position: ++position, input, trim }, ";"));
106
+ if (!subtype.length || !httpTokenCodePoints.test(subtype)) {
107
+ throw new TypeError(_MediaTypeParser.generateErrorMessage("subtype", subtype));
117
108
  }
118
- let parameterName = "", parameterValue = null;
109
+ let parameterName = "";
110
+ let parameterValue = null;
119
111
  const parameters = new MediaTypeParameters();
120
112
  while (position++ < length) {
121
113
  while (whitespaceCharacters.includes(input[position])) {
122
114
  ++position;
123
115
  }
124
- ({ position, result: parameterName } = _MediaTypeParser.#filterComponent({ position, input, lowerCase }, ";", "="));
116
+ ({ position, result: parameterName } = _MediaTypeParser.filterComponent({ position, input, lowerCase }, ";", "="));
125
117
  if (position < length) {
126
118
  if (input[position] == ";") {
127
119
  continue;
128
120
  }
129
121
  ++position;
130
122
  }
131
- if (input[position] == '"') {
132
- [parameterValue, position] = _MediaTypeParser.#collectHttpQuotedString(input, position);
133
- while (position < length && input[position] != ";") {
123
+ if (input[position] === '"') {
124
+ [parameterValue, position] = _MediaTypeParser.collectHttpQuotedString(input, position);
125
+ while (position < length && input[position] !== ";") {
134
126
  ++position;
135
127
  }
136
128
  } else {
137
- ({ position, result: parameterValue } = _MediaTypeParser.#filterComponent({ position, input, lowerCase, trim }, ";"));
129
+ ({ position, result: parameterValue } = _MediaTypeParser.filterComponent({ position, input, lowerCase, trim }, ";"));
138
130
  if (!parameterValue) {
139
131
  continue;
140
132
  }
141
133
  }
142
- if (parameterName && MediaTypeParameters.isValid(parameterName, parameterValue) && !parameters.has(parameterName)) {
134
+ if (parameterName && parameterValue !== null && MediaTypeParameters.isValid(parameterName, parameterValue) && !parameters.has(parameterName)) {
143
135
  parameters.set(parameterName, parameterValue);
144
136
  }
145
137
  }
146
138
  return { type, subtype, parameters };
147
139
  }
140
+ /**
141
+ * Gets the name of this class.
142
+ * @returns The string tag of this class.
143
+ */
144
+ get [Symbol.toStringTag]() {
145
+ return "MediaTypeParser";
146
+ }
148
147
  /**
149
148
  * Filters a component from the input string.
150
- *
151
- * @private
152
- * @static
153
- * @param {Object} options The options.
154
- * @param {number} [options.position] The starting position.
155
- * @param {string} options.input The input string.
156
- * @param {boolean} [options.lowerCase] Indicates whether the result should be lowercased.
157
- * @param {boolean} [options.trim] Indicates whether the result should be trimmed.
158
- * @param {string[]} charactersToFilter The characters to filter.
159
- * @returns {{ position: number, result: string }} An object that includes the resulting string and updated position.
149
+ * @param options The options.
150
+ * @param charactersToFilter The characters to filter.
151
+ * @returns An object that includes the resulting string and updated position.
160
152
  */
161
- static #filterComponent({ position = 0, input, lowerCase = true, trim = false }, ...charactersToFilter) {
153
+ static filterComponent({ position = 0, input, lowerCase = true, trim = false }, ...charactersToFilter) {
162
154
  let result = "";
163
155
  for (const length = input.length; position < length && !charactersToFilter.includes(input[position]); position++) {
164
156
  result += input[position];
@@ -174,17 +166,14 @@ var MediaTypeParser = class _MediaTypeParser {
174
166
  /**
175
167
  * Collects all the HTTP quoted strings.
176
168
  * This variant only implements it with the extract-value flag set.
177
- *
178
- * @private
179
- * @static
180
- * @param {string} input The string to process.
181
- * @param {number} position The starting position.
182
- * @returns {Array<string|number>} An array that includes the resulting string and updated position.
169
+ * @param input The string to process.
170
+ * @param position The starting position.
171
+ * @returns An array that includes the resulting string and updated position.
183
172
  */
184
- static #collectHttpQuotedString(input, position) {
173
+ static collectHttpQuotedString(input, position) {
185
174
  let value = "";
186
175
  for (let length = input.length, char; ++position < length; ) {
187
- if ((char = input[position]) == '"') {
176
+ if ((char = input[position]) === '"') {
188
177
  break;
189
178
  }
190
179
  value += char == "\\" && ++position < length ? input[position] : char;
@@ -193,107 +182,102 @@ var MediaTypeParser = class _MediaTypeParser {
193
182
  }
194
183
  /**
195
184
  * Generates an error message.
196
- *
197
- * @private
198
- * @static
199
- * @param {string} component The component name.
200
- * @param {string} value The component value.
201
- * @returns {string} The error message.
185
+ * @param component The component name.
186
+ * @param value The component value.
187
+ * @returns The error message.
202
188
  */
203
- static #generateErrorMessage(component, value) {
189
+ static generateErrorMessage(component, value) {
204
190
  return `Invalid ${component} "${value}": only HTTP token code points are valid.`;
205
191
  }
206
192
  };
207
193
 
208
- // src/media-type.js
194
+ // src/media-type.ts
209
195
  var MediaType = class _MediaType {
210
- /** @type {string} */
211
- #type;
212
- /** @type {string} */
213
- #subtype;
214
- /** @type {MediaTypeParameters} */
215
- #parameters;
196
+ _type;
197
+ _subtype;
198
+ _parameters;
216
199
  /**
217
200
  * Create a new MediaType instance from a string representation.
218
- *
219
- * @param {string} mediaType The media type to parse.
220
- * @param {Object} [parameters] Optional parameters.
201
+ * @param mediaType The media type to parse.
202
+ * @param parameters Optional parameters.
221
203
  */
222
204
  constructor(mediaType, parameters = {}) {
223
- if (object_type_default(parameters) != Object) {
205
+ if (parameters === null || typeof parameters !== "object" || Array.isArray(parameters)) {
224
206
  throw new TypeError("The parameters argument must be an object");
225
207
  }
226
- ({ type: this.#type, subtype: this.#subtype, parameters: this.#parameters } = MediaTypeParser.parse(mediaType));
208
+ ({ type: this._type, subtype: this._subtype, parameters: this._parameters } = MediaTypeParser.parse(mediaType));
227
209
  for (const [name, value] of Object.entries(parameters)) {
228
- this.#parameters.set(name, value);
210
+ this._parameters.set(name, value);
229
211
  }
230
212
  }
213
+ /**
214
+ * Parses a media type string.
215
+ * @param mediaType The media type to parse.
216
+ * @returns The parsed media type or null if the mediaType cannot be parsed.
217
+ */
231
218
  static parse(mediaType) {
232
219
  try {
233
220
  return new _MediaType(mediaType);
234
- } catch (e) {
221
+ } catch {
235
222
  }
236
223
  return null;
237
224
  }
238
225
  /**
239
226
  * Gets the type.
240
- *
241
- * @returns {string} The type.
227
+ * @returns The type.
242
228
  */
243
229
  get type() {
244
- return this.#type;
230
+ return this._type;
245
231
  }
246
232
  /**
247
233
  * Gets the subtype.
248
- *
249
- * @returns {string} The subtype.
234
+ * @returns The subtype.
250
235
  */
251
236
  get subtype() {
252
- return this.#subtype;
237
+ return this._subtype;
253
238
  }
254
239
  /**
255
240
  * Gets the media type essence (type/subtype).
256
- *
257
- * @returns {string} The media type without any parameters
241
+ * @returns The media type without any parameters
258
242
  */
259
243
  get essence() {
260
- return `${this.#type}/${this.#subtype}`;
244
+ return `${this._type}/${this._subtype}`;
261
245
  }
262
246
  /**
263
247
  * Gets the parameters.
264
- *
265
- * @returns {MediaTypeParameters} The media type parameters.
248
+ * @returns The media type parameters.
266
249
  */
267
250
  get parameters() {
268
- return this.#parameters;
251
+ return this._parameters;
269
252
  }
270
253
  /**
271
254
  * Checks if the media type matches the specified type.
272
255
  *
273
- * @todo Fix string handling to parse the type and subtype from the string.
274
- * @param {MediaType|string} mediaType The media type to check.
275
- * @returns {boolean} true if the media type matches the specified type, false otherwise.
256
+ * @param mediaType The media type to check.
257
+ * @returns true if the media type matches the specified type, false otherwise.
276
258
  */
277
259
  matches(mediaType) {
278
- return this.#type === mediaType?.type && this.#subtype === mediaType?.subtype || this.essence.includes(mediaType);
260
+ return typeof mediaType === "string" ? this.essence.includes(mediaType) : this._type === mediaType._type && this._subtype === mediaType._subtype;
279
261
  }
280
262
  /**
281
263
  * Gets the serialized version of the media type.
282
264
  *
283
- * @returns {string} The serialized media type.
265
+ * @returns The serialized media type.
284
266
  */
285
267
  toString() {
286
- return `${this.essence}${this.#parameters.toString()}`;
268
+ return `${this.essence}${this._parameters.toString()}`;
287
269
  }
288
270
  /**
289
271
  * Gets the name of the class.
290
- *
291
- * @returns {string} The class name
272
+ * @returns The class name
292
273
  */
293
274
  get [Symbol.toStringTag]() {
294
275
  return "MediaType";
295
276
  }
296
277
  };
297
278
  export {
298
- MediaType as default
279
+ MediaType,
280
+ MediaTypeParameters,
281
+ MediaTypeParser
299
282
  };
283
+ //# sourceMappingURL=media-type.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/utils.ts", "../src/media-type-parameters.ts", "../src/media-type-parser.ts", "../src/media-type.ts"],
4
+ "sourcesContent": ["export const httpTokenCodePoints: RegExp = /^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u;", "import { httpTokenCodePoints } from './utils.js';\n\nconst matcher: RegExp = /([\"\\\\])/ug;\nconst httpQuotedStringTokenCodePoints: RegExp = /^[\\t\\u0020-\\u007E\\u0080-\\u00FF]*$/u;\n\n/**\n * Class representing the parameters for a media type record.\n * This class extends a JavaScript Map<string, string>.\n *\n * However, MediaTypeParameters methods will always interpret their arguments\n * as appropriate for media types, so parameter names will be lowercased,\n * and attempting to set invalid characters will throw an Error.\n *\n * @see https://mimesniff.spec.whatwg.org\n * @author D1g1talEntr0py <jason.dimeo@gmail.com>\n */\nexport class MediaTypeParameters extends Map<string, string> {\n\t/**\n\t * Create a new MediaTypeParameters instance.\n\t *\n\t * @param entries An array of [ name, value ] tuples.\n\t */\n\tconstructor(entries: Iterable<[string, string]> = []) {\n\t\tsuper(entries);\n\t}\n\n\t/**\n\t * Indicates whether the supplied name and value are valid media type parameters.\n\t *\n\t * @param name The name of the media type parameter to validate.\n\t * @param value The media type parameter value to validate.\n\t * @returns true if the media type parameter is valid, false otherwise.\n\t */\n\tstatic isValid(name: string, value: string): boolean {\n\t\treturn httpTokenCodePoints.test(name) && httpQuotedStringTokenCodePoints.test(value);\n\t}\n\n\t/**\n\t * Gets the media type parameter value for the supplied name.\n\t *\n\t * @param name The name of the media type parameter to retrieve.\n\t * @returns The media type parameter value.\n\t */\n\toverride get(name: string): string | undefined {\n\t\treturn super.get(name.toLowerCase());\n\t}\n\n\t/**\n\t * Indicates whether the media type parameter with the specified name exists or not.\n\t *\n\t * @param name The name of the media type parameter to check.\n\t * @returns true if the media type parameter exists, false otherwise.\n\t */\n\toverride has(name: string): boolean {\n\t\treturn super.has(name.toLowerCase());\n\t}\n\n\t/**\n\t * Adds a new media type parameter using the specified name and value to the MediaTypeParameters.\n\t * If an parameter with the same name already exists, the parameter will be updated.\n\t *\n\t * @param name The name of the media type parameter to set.\n\t * @param value The media type parameter value.\n\t * @returns This instance.\n\t */\n\toverride set(name: string, value: string): this {\n\t\tif (!MediaTypeParameters.isValid(name, value)) {\n\t\t\tthrow new Error(`Invalid media type parameter name/value: ${name}/${value}`);\n\t\t}\n\n\t\tsuper.set(name.toLowerCase(), value);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the media type parameter using the specified name.\n\t *\n\t * @param name The name of the media type parameter to delete.\n\t * @returns true if the parameter existed and has been removed, or false if the parameter does not exist.\n\t */\n\toverride delete(name: string): boolean {\n\t\treturn super.delete(name.toLowerCase());\n\t}\n\n\t/**\n\t * Returns a string representation of the media type parameters.\n\t *\n\t * @returns The string representation of the media type parameters.\n\t */\n\toverride toString(): string {\n\t\treturn Array.from(this).map(([ name, value ]) => `;${name}=${!value || !httpTokenCodePoints.test(value) ? `\"${value.replace(matcher, '\\\\$1')}\"` : value}`).join('');\n\t}\n\n\t/**\n\t * Returns the name of this class.\n\t *\n\t * @returns The name of this class.\n\t */\n\toverride get [Symbol.toStringTag](): string {\n\t\treturn 'MediaTypeParameters';\n\t}\n}", "import { MediaTypeParameters } from './media-type-parameters.js';\nimport { httpTokenCodePoints } from './utils.js';\n\nconst whitespaceCharacters: string[] = [' ', '\\t', '\\n', '\\r'];\nconst trailingWhitespace: RegExp = /[ \\t\\n\\r]+$/u;\nconst leadingAndTrailingWhitespace: RegExp = /^[ \\t\\n\\r]+|[ \\t\\n\\r]+$/ug;\n\nexport interface MediaTypeComponent {\n\tposition?: number;\n\tinput: string;\n\tlowerCase?: boolean;\n\ttrim?: boolean;\n}\n\nexport interface ParsedMediaType {\n\ttype: string;\n\tsubtype: string;\n\tparameters: MediaTypeParameters;\n}\n\n/**\n * Parser for media types.\n * @see https://mimesniff.spec.whatwg.org/#parsing-a-mime-type\n * @author D1g1talEntr0py <jason.dimeo@gmail.com>\n */\nexport class MediaTypeParser {\n\t/**\n\t * Function to parse a media type.\n\t * @param input The media type to parse\n\t * @returns An object populated with the parsed media type properties and any parameters.\n\t */\n\tstatic parse(input: string): ParsedMediaType {\n\t\tinput = input.replace(leadingAndTrailingWhitespace, '');\n\n\t\tconst length = input.length, trim = true, lowerCase = false;\n\t\tconst { position: initialPosition, result: type } = MediaTypeParser.filterComponent({ input }, '/');\n\t\tlet position = initialPosition;\n\n\t\tif (!type.length || position >= length || !httpTokenCodePoints.test(type)) {\n\t\t\tthrow new TypeError(MediaTypeParser.generateErrorMessage('type', type));\n\t\t}\n\n\t\tlet subtype = '';\n\t\t({ position, result: subtype } = MediaTypeParser.filterComponent({ position: ++position, input, trim }, ';')); // `++position` Skips past \"/\"\n\n\t\tif (!subtype.length || !httpTokenCodePoints.test(subtype)) {\n\t\t\tthrow new TypeError(MediaTypeParser.generateErrorMessage('subtype', subtype));\n\t\t}\n\n\t\tlet parameterName = '';\n\t\tlet parameterValue: string | null = null;\n\t\tconst parameters = new MediaTypeParameters();\n\n\t\twhile (position++ < length) { // `position++` Skips past \"/\"\n\t\t\twhile (whitespaceCharacters.includes(input[position]!)) { ++position }\n\n\t\t\t({ position, result: parameterName } = MediaTypeParser.filterComponent({ position, input, lowerCase }, ';', '='));\n\n\t\t\tif (position < length) {\n\t\t\t\tif (input[position] == ';') { continue }\n\n\t\t\t\t// Skip past \"=\"\n\t\t\t\t++position;\n\t\t\t}\n\n\t\t\tif (input[position] === '\"') {\n\t\t\t\t[ parameterValue, position ] = MediaTypeParser.collectHttpQuotedString(input, position);\n\n\t\t\t\twhile (position < length && input[position] !== ';') { ++position }\n\t\t\t} else {\n\t\t\t\t({ position, result: parameterValue } = MediaTypeParser.filterComponent({ position, input, lowerCase, trim }, ';'));\n\n\t\t\t\tif (!parameterValue) { continue }\n\t\t\t}\n\n\t\t\tif (parameterName && parameterValue !== null && MediaTypeParameters.isValid(parameterName, parameterValue) && !parameters.has(parameterName)) {\n\t\t\t\tparameters.set(parameterName, parameterValue);\n\t\t\t}\n\t\t}\n\n\t\treturn { type, subtype, parameters };\n\t}\n\n\t/**\n\t * Gets the name of this class.\n\t * @returns The string tag of this class.\n\t */\n\tget [Symbol.toStringTag](): string {\n\t\treturn 'MediaTypeParser';\n\t}\n\n\t/**\n\t * Filters a component from the input string.\n\t * @param options The options.\n\t * @param charactersToFilter The characters to filter.\n\t * @returns An object that includes the resulting string and updated position.\n\t */\n\tprivate static filterComponent({ position = 0, input, lowerCase = true, trim = false }: MediaTypeComponent, ...charactersToFilter: string[]): { position: number, result: string } {\n\t\tlet result = '';\n\t\tfor (const length = input.length; position < length && !charactersToFilter.includes(input[position]!); position++) {\n\t\t\tresult += input[position];\n\t\t}\n\n\t\tif (lowerCase) { result = result.toLowerCase() }\n\t\tif (trim) { result = result.replace(trailingWhitespace, '') }\n\n\t\treturn { position, result };\n\t}\n\n\t/**\n\t * Collects all the HTTP quoted strings.\n\t * This variant only implements it with the extract-value flag set.\n\t * @param input The string to process.\n\t * @param position The starting position.\n\t * @returns An array that includes the resulting string and updated position.\n\t */\n\tprivate static collectHttpQuotedString(input: string, position: number): [string, number] {\n\t\tlet value = '';\n\n\t\tfor (let length = input.length, char; ++position < length;) {\n\t\t\tif ((char = input[position]) === '\"') { break }\n\n\t\t\tvalue += char == '\\\\' && ++position < length ? input[position] : char;\n\t\t}\n\n\t\treturn [ value, position ];\n\t}\n\n\t/**\n\t * Generates an error message.\n\t * @param component The component name.\n\t * @param value The component value.\n\t * @returns The error message.\n\t */\n\tprivate static generateErrorMessage(component: string, value: string): string {\n\t\treturn `Invalid ${component} \"${value}\": only HTTP token code points are valid.`;\n\t}\n}", "import { MediaTypeParser } from './media-type-parser.js';\nimport { MediaTypeParameters } from './media-type-parameters.js';\n\n/**\n * Class used to parse media types.\n * @see https://mimesniff.spec.whatwg.org/#understanding-mime-types\n */\nexport class MediaType {\n\tprivate readonly _type: string;\n\tprivate readonly _subtype: string;\n\tprivate readonly _parameters: MediaTypeParameters;\n\n\t/**\n\t * Create a new MediaType instance from a string representation.\n\t * @param mediaType The media type to parse.\n\t * @param parameters Optional parameters.\n\t */\n\tconstructor(mediaType: string, parameters: Record<string, string> = {}) {\n\t\tif (parameters === null || typeof parameters !== 'object' || Array.isArray(parameters)) {\n\t\t\tthrow new TypeError('The parameters argument must be an object');\n\t\t}\n\n\t\t({ type: this._type, subtype: this._subtype, parameters: this._parameters } = MediaTypeParser.parse(mediaType));\n\n\t\tfor (const [ name, value ] of Object.entries(parameters)) { this._parameters.set(name, value) }\n\t}\n\n\t/**\n\t * Parses a media type string.\n\t * @param mediaType The media type to parse.\n\t * @returns The parsed media type or null if the mediaType cannot be parsed.\n\t */\n\tstatic parse(mediaType: string): MediaType | null {\n\t\ttry {\n\t\t\treturn new MediaType(mediaType);\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\n\t\treturn null;\n\t}\n\n\t/**\n\t * Gets the type.\n\t * @returns The type.\n\t */\n\tget type(): string {\n\t\treturn this._type;\n\t}\n\n\t/**\n\t * Gets the subtype.\n\t * @returns The subtype.\n\t */\n\tget subtype(): string {\n\t\treturn this._subtype;\n\t}\n\n\t/**\n\t * Gets the media type essence (type/subtype).\n\t * @returns The media type without any parameters\n\t */\n\tget essence(): string {\n\t\treturn `${this._type}/${this._subtype}`;\n\t}\n\n\t/**\n\t * Gets the parameters.\n\t * @returns The media type parameters.\n\t */\n\tget parameters(): MediaTypeParameters {\n\t\treturn this._parameters;\n\t}\n\n\t/**\n\t * Checks if the media type matches the specified type.\n\t *\n\t * @param mediaType The media type to check.\n\t * @returns true if the media type matches the specified type, false otherwise.\n\t */\n\tmatches(mediaType: MediaType | string): boolean {\n\t\treturn typeof mediaType === 'string' ? this.essence.includes(mediaType) : this._type === mediaType._type && this._subtype === mediaType._subtype;\n\t}\n\n\t/**\n\t * Gets the serialized version of the media type.\n\t *\n\t * @returns The serialized media type.\n\t */\n\ttoString(): string {\n\t\treturn `${this.essence}${this._parameters.toString()}`;\n\t}\n\n\t/**\n\t * Gets the name of the class.\n\t * @returns The class name\n\t */\n\tget [Symbol.toStringTag](): string {\n\t\treturn 'MediaType';\n\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,EAMA,IAAI,UAAkB;AACrB,WAAO,GAAG,KAAK,KAAK,IAAI,KAAK,QAAQ;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,aAAkC;AACrC,WAAO,KAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAQ,WAAwC;AAC/C,WAAO,OAAO,cAAc,WAAW,KAAK,QAAQ,SAAS,SAAS,IAAI,KAAK,UAAU,UAAU,SAAS,KAAK,aAAa,UAAU;AAAA,EACzI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAmB;AAClB,WAAO,GAAG,KAAK,OAAO,GAAG,KAAK,YAAY,SAAS,CAAC;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,OAAO,WAAW,IAAY;AAClC,WAAO;AAAA,EACR;AACD;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d1g1tal/media-type",
3
3
  "description": "Parses, serializes, and manipulates media types, according to the WHATWG MIME Sniffing Standard",
4
- "version": "5.0.2",
4
+ "version": "6.0.0",
5
5
  "author": "Domenic Denicola <d@domenic.me> (https://domenic.me/)",
6
6
  "maintainers": [
7
7
  {
@@ -14,65 +14,67 @@
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/D1g1talEntr0py/media-type.git"
16
16
  },
17
+ "bugs": {
18
+ "url": "https://github.com/D1g1talEntr0py/media-type/issues"
19
+ },
20
+ "homepage": "https://github.com/D1g1talEntr0py/media-type#readme",
17
21
  "publishConfig": {
18
22
  "access": "public"
19
23
  },
20
24
  "type": "module",
21
25
  "exports": {
22
- ".": "./src/media-type.js",
23
- "./*.js": "./src/*.js",
24
- "./dist/*": "./dist/*"
26
+ ".": {
27
+ "types": "./dist/media-type.d.ts",
28
+ "import": "./dist/media-type.js"
29
+ }
25
30
  },
26
31
  "files": [
27
32
  "/dist",
28
- "/src"
33
+ "README.md",
34
+ "LICENSE",
35
+ "CHANGELOG.md"
29
36
  ],
30
37
  "keywords": [
31
38
  "content-type",
32
39
  "mime type",
33
40
  "media type",
34
41
  "mimesniff",
42
+ "mime",
35
43
  "http",
36
- "whatwg"
44
+ "whatwg",
45
+ "typescript",
46
+ "esm",
47
+ "parser",
48
+ "serializer"
37
49
  ],
38
- "engines": {
39
- "node": ">=18"
40
- },
41
50
  "devDependencies": {
42
- "esbuild": "^0.20.1",
43
- "esbuild-library": "^1.0.7",
44
- "eslint": "^8.57.0",
45
- "eslint-plugin-compat": "^4.2.0",
46
- "eslint-plugin-jsdoc": "^48.2.0",
47
- "jest": "^29.7.0",
51
+ "@eslint/js": "^9.39.0",
52
+ "@types/node": "^24.9.2",
53
+ "@typescript-eslint/eslint-plugin": "^8.46.2",
54
+ "@typescript-eslint/parser": "^8.46.2",
55
+ "@typescript/lib-dom": "npm:@types/web@^0.0.288",
56
+ "@vitest/coverage-v8": "4.0.6",
57
+ "@vitest/ui": "^4.0.6",
58
+ "eslint": "^9.39.0",
59
+ "eslint-plugin-jsdoc": "^61.1.11",
48
60
  "printable-string": "^0.3.0",
61
+ "typescript": "^5.9.3",
62
+ "typescript-eslint": "^8.46.2",
63
+ "vitest": "^4.0.6",
49
64
  "whatwg-encoding": "^3.1.1"
50
65
  },
51
66
  "browserslist": [
52
67
  "defaults and fully supports es6-module",
53
68
  "maintained node versions"
54
69
  ],
55
- "jest": {
56
- "collectCoverage": true,
57
- "coverageDirectory": "./tests/coverage",
58
- "collectCoverageFrom": [
59
- "src/**/*.js"
60
- ],
61
- "testPathIgnorePatterns": [
62
- "tests/scripts"
63
- ],
64
- "coveragePathIgnorePatterns": [
65
- "/node_modules/"
66
- ]
67
- },
68
- "dependencies": {
69
- "@d1g1tal/chrysalis": "^2.4.0"
70
- },
71
70
  "scripts": {
72
- "build": "node ./esbuild.js",
73
- "test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
74
- "lint": "eslint --ext .js --fix --ignore-path .gitignore .",
75
- "coverage": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
76
- "pretest": "node tests/scripts/get-latest-platform-tests.js"
71
+ "build": "tsbuild",
72
+ "test": "vitest run",
73
+ "test:watch": "vitest",
74
+ "test:ui": "vitest run --ui",
75
+ "test:coverage": "vitest run --coverage",
76
+ "lint": "eslint",
77
+ "coverage": "vitest run --coverage",
78
+ "pretest": "node tests/scripts/get-latest-platform-tests.ts"
77
79
  }
78
80
  }
@@ -1,3 +0,0 @@
1
- var{toString:y}=Object.prototype,m=p=>p?.constructor??globalThis[y.call(p).slice(8,-1)]??p,u=/^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u,d=/(["\\])/ug,f=/^[\t\u0020-\u007E\u0080-\u00FF]*$/u,c=class h extends Map{constructor(e=[]){super(e)}static isValid(e,t){return u.test(e)&&f.test(t)}get(e){return super.get(e.toLowerCase())}has(e){return super.has(e.toLowerCase())}set(e,t){if(!h.isValid(e,t))throw Error(`Invalid media type parameter name/value: ${e}/${t}`);return super.set(e.toLowerCase(),t),this}delete(e){return super.delete(e.toLowerCase())}toString(){return Array.from(this).map(([e,t])=>`;${e}=${t&&u.test(t)?t:`"${t.replace(d,"\\$1")}"`}`).join("")}[Symbol.toStringTag](){return"MediaTypeParameters"}},$=[" "," ",`
2
- `,"\r"],b=/[ \t\n\r]+$/u,w=/^[ \t\n\r]+|[ \t\n\r]+$/ug,T=class o{static parse(e){let t=(e=e.replace(w,"")).length,{position:r,result:i,subtype:n=""}=o.#e({input:e},"/");if(!i.length||r>=t||!u.test(i))throw TypeError(o.#t("type",i));if({position:r,result:n}=o.#e({position:++r,input:e,trim:!0},";"),!n.length||!u.test(n))throw TypeError(o.#t("subtype",n));let s="",a=null,l=new c;for(;r++<t;){for(;$.includes(e[r]);)++r;if({position:r,result:s}=o.#e({position:r,input:e,lowerCase:!1},";","="),r<t){if(e[r]==";")continue;++r}if(e[r]=='"')for([a,r]=o.#r(e,r);r<t&&e[r]!=";";)++r;else if({position:r,result:a}=o.#e({position:r,input:e,lowerCase:!1,trim:!0},";"),!a)continue;s&&c.isValid(s,a)&&!l.has(s)&&l.set(s,a)}return{type:i,subtype:n,parameters:l}}static#e({position:e=0,input:t,lowerCase:r=!0,trim:i=!1},...n){let s="";for(let a=t.length;e<a&&!n.includes(t[e]);e++)s+=t[e];return r&&(s=s.toLowerCase()),i&&(s=s.replace(b,"")),{position:e,result:s}}static#r(e,t){let r="";for(let i=e.length,n;++t<i&&(n=e[t])!='"';)r+=n=="\\"&&++t<i?e[t]:n;return[r,t]}static#t(e,t){return`Invalid ${e} "${t}": only HTTP token code points are valid.`}},C=class g{#e;#r;#t;constructor(e,t={}){if(m(t)!=Object)throw TypeError("The parameters argument must be an object");for(let[r,i]of({type:this.#e,subtype:this.#r,parameters:this.#t}=T.parse(e),Object.entries(t)))this.#t.set(r,i)}static parse(e){try{return new g(e)}catch{}return null}get type(){return this.#e}get subtype(){return this.#r}get essence(){return`${this.#e}/${this.#r}`}get parameters(){return this.#t}matches(e){return this.#e===e?.type&&this.#r===e?.subtype||this.essence.includes(e)}toString(){return`${this.essence}${this.#t.toString()}`}get[Symbol.toStringTag](){return"MediaType"}};export{C as default};
3
- //# sourceMappingURL=media-type.min.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["media-type.js"],
4
- "sourcesContent": ["var{toString:e}=Object.prototype,t=t=>t?.constructor??globalThis[e.call(t).slice(8,-1)]??t,r=/^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u,s=/([\"\\\\])/ug,a=/^[\\t\\u0020-\\u007E\\u0080-\\u00FF]*$/u,n=class e extends Map{constructor(e=[]){super(e)}static isValid(e,t){return r.test(e)&&a.test(t)}get(e){return super.get(e.toLowerCase())}has(e){return super.has(e.toLowerCase())}set(t,r){if(!e.isValid(t,r))throw Error(`Invalid media type parameter name/value: ${t}/${r}`);return super.set(t.toLowerCase(),r),this}delete(e){return super.delete(e.toLowerCase())}toString(){return Array.from(this).map(([e,t])=>`;${e}=${t&&r.test(t)?t:`\"${t.replace(s,\"\\\\$1\")}\"`}`).join(\"\")}[Symbol.toStringTag](){return\"MediaTypeParameters\"}},i=[\" \",\"\t\",\"\\n\",\"\\r\"],o=/[ \\t\\n\\r]+$/u,u=/^[ \\t\\n\\r]+|[ \\t\\n\\r]+$/ug,l=class e{static parse(t){let s=(t=t.replace(u,\"\")).length,{position:a,result:o,subtype:l=\"\"}=e.#e({input:t},\"/\");if(!o.length||a>=s||!r.test(o))throw TypeError(e.#t(\"type\",o));if({position:a,result:l}=e.#e({position:++a,input:t,trim:!0},\";\"),!l.length||!r.test(l))throw TypeError(e.#t(\"subtype\",l));let p=\"\",c=null,h=new n;for(;a++<s;){for(;i.includes(t[a]);)++a;if({position:a,result:p}=e.#e({position:a,input:t,lowerCase:!1},\";\",\"=\"),a<s){if(\";\"==t[a])continue;++a}if('\"'==t[a])for([c,a]=e.#r(t,a);a<s&&\";\"!=t[a];)++a;else if({position:a,result:c}=e.#e({position:a,input:t,lowerCase:!1,trim:!0},\";\"),!c)continue;p&&n.isValid(p,c)&&!h.has(p)&&h.set(p,c)}return{type:o,subtype:l,parameters:h}}static #e({position:e=0,input:t,lowerCase:r=!0,trim:s=!1},...a){let n=\"\";for(let r=t.length;e<r&&!a.includes(t[e]);e++)n+=t[e];return r&&(n=n.toLowerCase()),s&&(n=n.replace(o,\"\")),{position:e,result:n}}static #r(e,t){let r=\"\";for(let s=e.length,a;++t<s&&'\"'!=(a=e[t]);)r+=\"\\\\\"==a&&++t<s?e[t]:a;return[r,t]}static #t(e,t){return`Invalid ${e} \"${t}\": only HTTP token code points are valid.`}},p=class e{#s;#a;#n;constructor(e,r={}){if(t(r)!=Object)throw TypeError(\"The parameters argument must be an object\");for(let[t,s]of({type:this.#s,subtype:this.#a,parameters:this.#n}=l.parse(e),Object.entries(r)))this.#n.set(t,s)}static parse(t){try{return new e(t)}catch(e){}return null}get type(){return this.#s}get subtype(){return this.#a}get essence(){return`${this.#s}/${this.#a}`}get parameters(){return this.#n}matches(e){return this.#s===e?.type&&this.#a===e?.subtype||this.essence.includes(e)}toString(){return`${this.essence}${this.#n.toString()}`}get[Symbol.toStringTag](){return\"MediaType\"}};export{p as default};"],
5
- "mappings": "AAAA,GAAG,CAAC,SAASA,CAAC,EAAE,OAAO,UAAUC,EAAEA,GAAGA,GAAG,aAAa,WAAWD,EAAE,KAAKC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,GAAGA,EAAEC,EAAE,iCAAiCC,EAAE,YAAYC,EAAE,qCAAqCC,EAAE,MAAML,UAAU,GAAG,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,QAAQ,EAAE,EAAE,CAAC,OAAOE,EAAE,KAAK,CAAC,GAAGE,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,MAAM,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,MAAM,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,IAAIH,EAAEC,EAAE,CAAC,GAAG,CAACF,EAAE,QAAQC,EAAEC,CAAC,EAAE,MAAM,MAAM,4CAA4CD,CAAC,IAAIC,CAAC,EAAE,EAAE,OAAO,MAAM,IAAID,EAAE,YAAY,EAAEC,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,OAAO,MAAM,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,MAAM,KAAK,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,GAAGA,EAAE,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQC,EAAE,MAAM,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,WAAW,GAAG,CAAC,MAAM,qBAAqB,CAAC,EAAEG,EAAE,CAAC,IAAI,IAAI;AAAA,EAAK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