@d1g1tal/media-type 4.0.0 → 4.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/README.md CHANGED
@@ -5,7 +5,7 @@ This package will parse [MIME types](https://mimesniff.spec.whatwg.org/#understa
5
5
  This version is using ES Modules instead of commonJS.
6
6
 
7
7
  ```js
8
- import { MediaType } from '@d1g1tal/mime-type';
8
+ import { MediaType } from '@d1g1tal/media-type';
9
9
 
10
10
  const mediaType = new MediaType(`Text/HTML;Charset="utf-8"`);
11
11
 
@@ -75,10 +75,10 @@ var MediaType = (() => {
75
75
  name = asciiLowercase(String(name));
76
76
  value = String(value);
77
77
  if (!solelyContainsHTTPTokenCodePoints(name)) {
78
- throw new Error(`Invalid MIME type parameter name "${name}": only HTTP token code points are valid.`);
78
+ throw new Error(`Invalid media type parameter name "${name}": only HTTP token code points are valid.`);
79
79
  }
80
80
  if (!solelyContainsHTTPQuotedStringTokenCodePoints(value)) {
81
- throw new Error(`Invalid MIME type parameter value "${value}": only HTTP quoted-string token code points are valid.`);
81
+ throw new Error(`Invalid media type parameter value "${value}": only HTTP quoted-string token code points are valid.`);
82
82
  }
83
83
  this._map.set(name, value);
84
84
  return this;
@@ -1,4 +1,4 @@
1
1
  var MediaType=(()=>{var m=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var b=(t,e)=>{for(var r in e)m(t,r,{get:e[r],enumerable:!0})},H=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of _(e))!P.call(t,n)&&n!==r&&m(t,n,{get:()=>e[n],enumerable:!(s=w(e,n))||s.enumerable});return t};var C=t=>H(m({},"__esModule",{value:!0}),t);var $={};b($,{default:()=>p});var u=t=>t.replace(/^[ \t\n\r]+/u,"").replace(/[ \t\n\r]+$/u,""),y=t=>t.replace(/[ \t\n\r]+$/u,""),T=t=>t===" "||t===" "||t===`
2
- `||t==="\r",i=t=>/^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u.test(t),h=t=>/^[\t\u0020-\u007E\u0080-\u00FF]*$/u.test(t),a=t=>t.replace(/[A-Z]/ug,e=>e.toLowerCase()),g=(t,e)=>{let r="";for(e++;;){for(;e<t.length&&t[e]!=='"'&&t[e]!=="\\";)r+=t[e],++e;if(e>=t.length)break;let s=t[e];if(++e,s==="\\"){if(e>=t.length){r+="\\";break}r+=t[e],++e}else break}return[r,e]};var c=class{constructor(e){this._map=e}get size(){return this._map.size}get(e){return this._map.get(a(String(e)))}has(e){return this._map.has(a(String(e)))}set(e,r){if(e=a(String(e)),r=String(r),!i(e))throw new Error(`Invalid MIME type parameter name "${e}": only HTTP token code points are valid.`);if(!h(r))throw new Error(`Invalid MIME type parameter value "${r}": only HTTP quoted-string token code points are valid.`);return this._map.set(e,r),this}clear(){this._map.clear()}delete(e){return e=a(String(e)),this._map.delete(e)}forEach(e,r){this._map.forEach(e,r)}keys(){return this._map.keys()}values(){return this._map.values()}entries(){return this._map.entries()}[Symbol.iterator](){return this._map[Symbol.iterator]()}};var S=t=>{t=u(t);let e=0,r="";for(;e<t.length&&t[e]!=="/";)r+=t[e],++e;if(r.length===0||!i(r)||e>=t.length)return null;++e;let s="";for(;e<t.length&&t[e]!==";";)s+=t[e],++e;if(s=y(s),s.length===0||!i(s))return null;let n={type:a(r),subtype:a(s),parameters:new Map};for(;e<t.length;){for(++e;T(t[e]);)++e;let l="";for(;e<t.length&&t[e]!==";"&&t[e]!=="=";)l+=t[e],++e;if(l=a(l),e<t.length){if(t[e]===";")continue;++e}let o=null;if(t[e]==='"')for([o,e]=g(t,e);e<t.length&&t[e]!==";";)++e;else{for(o="";e<t.length&&t[e]!==";";)o+=t[e],++e;if(o=y(o),o==="")continue}l.length>0&&i(l)&&h(o)&&!n.parameters.has(l)&&n.parameters.set(l,o)}return n},f=S;var k=t=>{let e=`${t.type}/${t.subtype}`;if(t.parameters.size===0)return e;for(let[r,s]of t.parameters)e+=";",e+=r,e+="=",(!i(s)||s.length===0)&&(s=s.replace(/(["\\])/ug,"\\$1"),s=`"${s}"`),e+=s;return e},d=k;var p=class{constructor(e){e=String(e);let r=f(e);if(r===null)throw new Error(`Could not parse media type string '${e}'`);this._type=r.type,this._subtype=r.subtype,this._parameters=new c(r.parameters)}static parse(e){try{return new this(e)}catch{return null}}get essence(){return`${this.type}/${this.subtype}`}get type(){return this._type}set type(e){if(e=a(String(e)),e.length===0)throw new Error("Invalid type: must be a non-empty string");if(!i(e))throw new Error(`Invalid type ${e}: must contain only HTTP token code points`);this._type=e}get subtype(){return this._subtype}set subtype(e){if(e=a(String(e)),e.length===0)throw new Error("Invalid subtype: must be a non-empty string");if(!i(e))throw new Error(`Invalid subtype ${e}: must contain only HTTP token code points`);this._subtype=e}get parameters(){return this._parameters}toString(){return d(this)}isJavaScript({prohibitParameters:e=!1}={}){switch(this._type){case"text":switch(this._subtype){case"ecmascript":case"javascript":case"javascript1.0":case"javascript1.1":case"javascript1.2":case"javascript1.3":case"javascript1.4":case"javascript1.5":case"jscript":case"livescript":case"x-ecmascript":case"x-javascript":return!e||this._parameters.size===0;default:return!1}case"application":switch(this._subtype){case"ecmascript":case"javascript":case"x-ecmascript":case"x-javascript":return!e||this._parameters.size===0;default:return!1}default:return!1}}isXML(){return this._subtype==="xml"&&(this._type==="text"||this._type==="application")||this._subtype.endsWith("+xml")}isHTML(){return this._subtype==="html"&&this._type==="text"}get[Symbol.toStringTag](){return"MediaType"}};return C($);})();
2
+ `||t==="\r",i=t=>/^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u.test(t),h=t=>/^[\t\u0020-\u007E\u0080-\u00FF]*$/u.test(t),a=t=>t.replace(/[A-Z]/ug,e=>e.toLowerCase()),g=(t,e)=>{let r="";for(e++;;){for(;e<t.length&&t[e]!=='"'&&t[e]!=="\\";)r+=t[e],++e;if(e>=t.length)break;let s=t[e];if(++e,s==="\\"){if(e>=t.length){r+="\\";break}r+=t[e],++e}else break}return[r,e]};var c=class{constructor(e){this._map=e}get size(){return this._map.size}get(e){return this._map.get(a(String(e)))}has(e){return this._map.has(a(String(e)))}set(e,r){if(e=a(String(e)),r=String(r),!i(e))throw new Error(`Invalid media type parameter name "${e}": only HTTP token code points are valid.`);if(!h(r))throw new Error(`Invalid media type parameter value "${r}": only HTTP quoted-string token code points are valid.`);return this._map.set(e,r),this}clear(){this._map.clear()}delete(e){return e=a(String(e)),this._map.delete(e)}forEach(e,r){this._map.forEach(e,r)}keys(){return this._map.keys()}values(){return this._map.values()}entries(){return this._map.entries()}[Symbol.iterator](){return this._map[Symbol.iterator]()}};var S=t=>{t=u(t);let e=0,r="";for(;e<t.length&&t[e]!=="/";)r+=t[e],++e;if(r.length===0||!i(r)||e>=t.length)return null;++e;let s="";for(;e<t.length&&t[e]!==";";)s+=t[e],++e;if(s=y(s),s.length===0||!i(s))return null;let n={type:a(r),subtype:a(s),parameters:new Map};for(;e<t.length;){for(++e;T(t[e]);)++e;let l="";for(;e<t.length&&t[e]!==";"&&t[e]!=="=";)l+=t[e],++e;if(l=a(l),e<t.length){if(t[e]===";")continue;++e}let o=null;if(t[e]==='"')for([o,e]=g(t,e);e<t.length&&t[e]!==";";)++e;else{for(o="";e<t.length&&t[e]!==";";)o+=t[e],++e;if(o=y(o),o==="")continue}l.length>0&&i(l)&&h(o)&&!n.parameters.has(l)&&n.parameters.set(l,o)}return n},d=S;var k=t=>{let e=`${t.type}/${t.subtype}`;if(t.parameters.size===0)return e;for(let[r,s]of t.parameters)e+=";",e+=r,e+="=",(!i(s)||s.length===0)&&(s=s.replace(/(["\\])/ug,"\\$1"),s=`"${s}"`),e+=s;return e},f=k;var p=class{constructor(e){e=String(e);let r=d(e);if(r===null)throw new Error(`Could not parse media type string '${e}'`);this._type=r.type,this._subtype=r.subtype,this._parameters=new c(r.parameters)}static parse(e){try{return new this(e)}catch{return null}}get essence(){return`${this.type}/${this.subtype}`}get type(){return this._type}set type(e){if(e=a(String(e)),e.length===0)throw new Error("Invalid type: must be a non-empty string");if(!i(e))throw new Error(`Invalid type ${e}: must contain only HTTP token code points`);this._type=e}get subtype(){return this._subtype}set subtype(e){if(e=a(String(e)),e.length===0)throw new Error("Invalid subtype: must be a non-empty string");if(!i(e))throw new Error(`Invalid subtype ${e}: must contain only HTTP token code points`);this._subtype=e}get parameters(){return this._parameters}toString(){return f(this)}isJavaScript({prohibitParameters:e=!1}={}){switch(this._type){case"text":switch(this._subtype){case"ecmascript":case"javascript":case"javascript1.0":case"javascript1.1":case"javascript1.2":case"javascript1.3":case"javascript1.4":case"javascript1.5":case"jscript":case"livescript":case"x-ecmascript":case"x-javascript":return!e||this._parameters.size===0;default:return!1}case"application":switch(this._subtype){case"ecmascript":case"javascript":case"x-ecmascript":case"x-javascript":return!e||this._parameters.size===0;default:return!1}default:return!1}}isXML(){return this._subtype==="xml"&&(this._type==="text"||this._type==="application")||this._subtype.endsWith("+xml")}isHTML(){return this._subtype==="html"&&this._type==="text"}get[Symbol.toStringTag](){return"MediaType"}};return C($);})();
3
3
  window.MediaType = MediaType.default;
4
4
  //# sourceMappingURL=media-type.min.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/media-type.js", "../src/utils.js", "../src/media-type-parameters.js", "../src/parser.js", "../src/serializer.js"],
4
- "sourcesContent": ["import MediaTypeParameters from './media-type-parameters.js';\nimport parse from './parser.js';\nimport serialize from './serializer.js';\nimport { asciiLowercase, solelyContainsHTTPTokenCodePoints } from './utils.js';\n\n/**\n * Class used to parse media types.\n *\n * @see https://mimesniff.spec.whatwg.org/#understanding-mime-types\n * @module MediaType\n */\nexport default class MediaType {\n\t/**\n\t * Create a new MediaType instance from a string representation.\n\t *\n\t * @param {string} string The media type to parse\n\t */\n\tconstructor(string) {\n\t\tstring = String(string);\n\t\tconst result = parse(string);\n\t\tif (result === null) {\n\t\t\tthrow new Error(`Could not parse media type string '${string}'`);\n\t\t}\n\n\t\tthis._type = result.type;\n\t\tthis._subtype = result.subtype;\n\t\tthis._parameters = new MediaTypeParameters(result.parameters);\n\t}\n\n\t/**\n\t * Static factor method for parsing a media type.\n\t *\n\t * @param {string} string The media type to parse\n\t * @returns {MediaType} The parsed {@link MediaType} object\n\t */\n\tstatic parse(string) {\n\t\ttry {\n\t\t\treturn new this(string);\n\t\t} catch (e) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Gets the media type essence (type/subtype).\n\t *\n\t * @returns {string} The media type without any parameters\n\t */\n\tget essence() {\n\t\treturn `${this.type}/${this.subtype}`;\n\t}\n\n\t/**\n\t * Gets the type.\n\t *\n\t * @returns {string} The type.\n\t */\n\tget type() {\n\t\treturn this._type;\n\t}\n\n\t/**\n\t * Sets the type.\n\t */\n\tset type(value) {\n\t\tvalue = asciiLowercase(String(value));\n\n\t\tif (value.length === 0) {\n\t\t\tthrow new Error('Invalid type: must be a non-empty string');\n\t\t}\n\t\tif (!solelyContainsHTTPTokenCodePoints(value)) {\n\t\t\tthrow new Error(`Invalid type ${value}: must contain only HTTP token code points`);\n\t\t}\n\n\t\tthis._type = value;\n\t}\n\n\t/**\n\t * Gets the subtype.\n\t *\n\t * @returns {string} The subtype.\n\t */\n\tget subtype() {\n\t\treturn this._subtype;\n\t}\n\n\t/**\n\t * Sets the subtype.\n\t */\n\tset subtype(value) {\n\t\tvalue = asciiLowercase(String(value));\n\n\t\tif (value.length === 0) {\n\t\t\tthrow new Error('Invalid subtype: must be a non-empty string');\n\t\t}\n\t\tif (!solelyContainsHTTPTokenCodePoints(value)) {\n\t\t\tthrow new Error(`Invalid subtype ${value}: must contain only HTTP token code points`);\n\t\t}\n\n\t\tthis._subtype = value;\n\t}\n\n\t/**\n\t * Gets the parameters.\n\t *\n\t * @returns {MediaTypeParameters} The media type parameters.\n\t */\n\tget parameters() {\n\t\treturn this._parameters;\n\t}\n\n\t/**\n\t * Gets the serialized version of the media type.\n\t *\n\t * @returns {string} The serialized media type.\n\t */\n\ttoString() {\n\t\t// The serialize function works on both 'media type records' (i.e. the results of parse) and on this class, since\n\t\t// this class's interface is identical.\n\t\treturn serialize(this);\n\t}\n\n\t/**\n\t * Determines if this instance is a JavaScript media type.\n\t *\n\t * @param {Object} [options] Optional options.\n\t * @param {boolean} [options.prohibitParameters=false] The option to prohibit parameters when checking if the media type is JavaScript.\n\t * @returns {boolean} true if this instance represents a JavaScript media type, false otherwise.\n\t */\n\tisJavaScript({prohibitParameters = false} = {}) {\n\t\tswitch (this._type) {\n\t\t\tcase 'text': {\n\t\t\t\tswitch (this._subtype) {\n\t\t\t\t\tcase 'ecmascript':\n\t\t\t\t\tcase 'javascript':\n\t\t\t\t\tcase 'javascript1.0':\n\t\t\t\t\tcase 'javascript1.1':\n\t\t\t\t\tcase 'javascript1.2':\n\t\t\t\t\tcase 'javascript1.3':\n\t\t\t\t\tcase 'javascript1.4':\n\t\t\t\t\tcase 'javascript1.5':\n\t\t\t\t\tcase 'jscript':\n\t\t\t\t\tcase 'livescript':\n\t\t\t\t\tcase 'x-ecmascript':\n\t\t\t\t\tcase 'x-javascript': return !prohibitParameters || this._parameters.size === 0;\n\t\t\t\t\tdefault: return false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcase 'application': {\n\t\t\t\tswitch (this._subtype) {\n\t\t\t\t\tcase 'ecmascript':\n\t\t\t\t\tcase 'javascript':\n\t\t\t\t\tcase 'x-ecmascript':\n\t\t\t\t\tcase 'x-javascript': return !prohibitParameters || this._parameters.size === 0;\n\t\t\t\t\tdefault: return false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdefault: return false;\n\t\t}\n\t}\n\n\t/**\n\t * Determines if this instance is an XML media type.\n\t *\n\t * @returns {boolean} true if this instance represents an XML media type, false otherwise.\n\t */\n\tisXML() {\n\t\treturn (this._subtype === 'xml' && (this._type === 'text' || this._type === 'application')) || this._subtype.endsWith('+xml');\n\t}\n\n\t/**\n\t * Determines if this instance is an HTML media type.\n\t *\n\t * @returns {boolean} true if this instance represents an HTML media type, false otherwise.\n\t */\n\tisHTML() {\n\t\treturn this._subtype === 'html' && this._type === 'text';\n\t}\n\n\t/**\n\t * Gets the name of the class.\n\t *\n\t * @returns {string} The class name\n\t */\n\tget [Symbol.toStringTag]() {\n\t\treturn 'MediaType';\n\t}\n}", "/** @module utils */\n\n/**\n * A function to remove any leading and trailing HTTP whitespace.\n *\n * @param {string} string The string to process.\n * @returns {string} The processed string.\n */\nconst removeLeadingAndTrailingHTTPWhitespace = (string) => string.replace(/^[ \\t\\n\\r]+/u, '').replace(/[ \\t\\n\\r]+$/u, '');\n\n/**\n * A function to remove any trailing HTTP whitespace.\n *\n * @param {string} string The string to process.\n * @returns {string} The processed string.\n */\nconst removeTrailingHTTPWhitespace = (string) => string.replace(/[ \\t\\n\\r]+$/u, '');\n\n/**\n * Determines if the provided character is whitespace.\n *\n * @param {string} char The character to evaluate.\n * @returns {boolean} true if the character is whitespace, false otherwise.\n */\nconst isHTTPWhitespaceChar = (char) => char === ' ' || char === '\\t' || char === '\\n' || char === '\\r';\n\n/**\n * Determines if the provided string contains only HTTP token code points.\n *\n * @param {string} string The string to evaluate.\n * @returns {boolean} true if the string contains only HTTP token code points.\n */\nconst solelyContainsHTTPTokenCodePoints = (string) => /^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u.test(string);\n\n/**\n * Determines if the provided string contains only quoted HTTP token code points.\n *\n * @param {string} string The string to evaluate.\n * @returns {boolean} true if the string contains only quoted HTTP token code points.\n */\nconst solelyContainsHTTPQuotedStringTokenCodePoints = (string) => /^[\\t\\u0020-\\u007E\\u0080-\\u00FF]*$/u.test(string);\n\n/**\n * A function to lower case ASCII characters.\n *\n * @param {string} string The string to process.\n * @returns {string} The processed string with all ASCII characters lower cased.\n */\nconst asciiLowercase = (string) => string.replace(/[A-Z]/ug, l => l.toLowerCase());\n\n/**\n * Collects all the HTTP quoted strings.\n * This variant only implements it with the extract-value flag set.\n *\n * @param {string} input The string to process.\n * @param {number} position The starting position.\n * @returns {Array<string | number>} An array that includes the resulting string and updated position.\n */\nconst collectAnHTTPQuotedString = (input, position) => {\n\tlet value = '';\n\n\tposition++;\n\n\twhile (true) {\n\t\twhile (position < input.length && input[position] !== '\"' && input[position] !== '\\\\') {\n\t\t\tvalue += input[position];\n\t\t\t++position;\n\t\t}\n\n\t\tif (position >= input.length) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst quoteOrBackslash = input[position];\n\t\t++position;\n\n\t\tif (quoteOrBackslash === '\\\\') {\n\t\t\tif (position >= input.length) {\n\t\t\t\tvalue += '\\\\';\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tvalue += input[position];\n\t\t\t++position;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn [value, position];\n};\n\nexport { removeLeadingAndTrailingHTTPWhitespace, removeTrailingHTTPWhitespace, isHTTPWhitespaceChar, solelyContainsHTTPTokenCodePoints, solelyContainsHTTPQuotedStringTokenCodePoints, asciiLowercase, collectAnHTTPQuotedString };\n", "import { asciiLowercase, solelyContainsHTTPQuotedStringTokenCodePoints, solelyContainsHTTPTokenCodePoints } from './utils.js';\n\n/**\n * Class representing the parameters for a MIME type record.\n * This class has the equivalent surface API to a JavaScript {@link Map}.\n *\n * However, {@link MediaTypeParameters} methods will always interpret their arguments\n * as appropriate for MIME types, so parameter names will be lowercased,\n * and attempting to set invalid characters will throw an {@link Error}.\n *\n * @example charset=utf-8\n * @module MediaTypeParameters\n */\nexport default class MediaTypeParameters {\n\t/**\n\t * Create a new MediaTypeParameters instance.\n\t *\n\t * @param {Map.<string, string>} map The map of parameters for a MIME type.\n\t */\n\tconstructor(map) {\n\t\tthis._map = map;\n\t}\n\n\t/**\n\t * Gets the number of MIME type parameters.\n\t *\n\t * @returns {number} The number of MIME type parameters\n\t */\n\tget size() {\n\t\treturn this._map.size;\n\t}\n\n\t/**\n\t * Gets the MIME type parameter value for the supplied name.\n\t *\n\t * @param {string} name The name of the MIME type parameter to retrieve.\n\t * @returns {string} The MIME type parameter value.\n\t */\n\tget(name) {\n\t\treturn this._map.get(asciiLowercase(String(name)));\n\t}\n\n\t/**\n\t * Indicates whether the MIME type parameter with the specified name exists or not.\n\t *\n\t * @param {string} name The name of the MIME type parameter to check.\n\t * @returns {boolean} true if the MIME type parameter exists, false otherwise.\n\t */\n\thas(name) {\n\t\treturn this._map.has(asciiLowercase(String(name)));\n\t}\n\n\t/**\n\t * Adds a new MIME 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 {string} name The name of the MIME type parameter to set.\n\t * @param {string} value The MIME type parameter value.\n\t * @returns {MediaTypeParameters} This instance.\n\t */\n\tset(name, value) {\n\t\tname = asciiLowercase(String(name));\n\t\tvalue = String(value);\n\n\t\tif (!solelyContainsHTTPTokenCodePoints(name)) {\n\t\t\tthrow new Error(`Invalid MIME type parameter name \"${name}\": only HTTP token code points are valid.`);\n\t\t}\n\n\t\tif (!solelyContainsHTTPQuotedStringTokenCodePoints(value)) {\n\t\t\tthrow new Error(`Invalid MIME type parameter value \"${value}\": only HTTP quoted-string token code points are valid.`);\n\t\t}\n\n\t\tthis._map.set(name, value);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Clears all the MIME type parameters.\n\t */\n\tclear() {\n\t\tthis._map.clear();\n\t}\n\n\t/**\n\t * Removes the MIME type parameter using the specified name.\n\t *\n\t * @param {string} name The name of the MIME type parameter to delete.\n\t * @returns {boolean} true if the parameter existed and has been removed, or false if the parameter does not exist.\n\t */\n\tdelete(name) {\n\t\tname = asciiLowercase(String(name));\n\t\treturn this._map.delete(name);\n\t}\n\n\t/**\n\t * Executes a provided function once per each name/value pair in the MediaTypeParameters, in insertion order.\n\t *\n\t * @param {function(string, string): void} callback The function called on each iteration.\n\t * @param {*} [thisArg] Optional object when binding 'this' to the callback.\n\t */\n\tforEach(callback, thisArg) {\n\t\tthis._map.forEach(callback, thisArg);\n\t}\n\n\t/**\n\t * Returns an iterable of parameter names.\n\t *\n\t * @returns {IterableIterator<string>} The {@link IterableIterator} of MIME type parameter names.\n\t */\n\tkeys() {\n\t\treturn this._map.keys();\n\t}\n\n\t/**\n\t * Returns an iterable of parameter values.\n\t *\n\t * @returns {IterableIterator<string>} The {@link IterableIterator} of MIME type parameter values.\n\t */\n\tvalues() {\n\t\treturn this._map.values();\n\t}\n\n\t/**\n\t * Returns an iterable of name, value pairs for every parameter entry in the MIME type parameters.\n\t *\n\t * @returns {IterableIterator<Array<Array<string>>>} The MIME type parameter entries.\n\t */\n\tentries() {\n\t\treturn this._map.entries();\n\t}\n\n\t/**\n\t * A method that returns the default iterator for the {@link MediaTypeParameters}. Called by the semantics of the for-of statement.\n\t *\n\t * @returns {Iterator<string, string, undefined>} The {@link Symbol.iterator} for the MIME type parameters.\n\t */\n\t[Symbol.iterator]() {\n\t\treturn this._map[Symbol.iterator]();\n\t}\n}", "import {\n\tasciiLowercase,\n\tcollectAnHTTPQuotedString, isHTTPWhitespaceChar, removeLeadingAndTrailingHTTPWhitespace,\n\tremoveTrailingHTTPWhitespace, solelyContainsHTTPQuotedStringTokenCodePoints, solelyContainsHTTPTokenCodePoints\n} from './utils.js';\n\n/**\n * Function to parse a media type.\n *\n * @module parser\n * @param {string} input The media type to parse\n * @returns {{ type: string, subtype: string, parameters: Map<string, string> }} An object populated with the parsed media type properties and any parameters.\n */\nconst parse = (input) => {\n\tinput = removeLeadingAndTrailingHTTPWhitespace(input);\n\n\tlet position = 0;\n\tlet type = '';\n\twhile (position < input.length && input[position] !== '/') {\n\t\ttype += input[position];\n\t\t++position;\n\t}\n\n\tif (type.length === 0 || !solelyContainsHTTPTokenCodePoints(type)) {\n\t\treturn null;\n\t}\n\n\tif (position >= input.length) {\n\t\treturn null;\n\t}\n\n\t// Skips past \"/\"\n\t++position;\n\n\tlet subtype = '';\n\twhile (position < input.length && input[position] !== ';') {\n\t\tsubtype += input[position];\n\t\t++position;\n\t}\n\n\tsubtype = removeTrailingHTTPWhitespace(subtype);\n\n\tif (subtype.length === 0 || !solelyContainsHTTPTokenCodePoints(subtype)) {\n\t\treturn null;\n\t}\n\n\tconst mediaType = {\n\t\ttype: asciiLowercase(type),\n\t\tsubtype: asciiLowercase(subtype),\n\t\tparameters: new Map()\n\t};\n\n\twhile (position < input.length) {\n\t\t// Skip past \";\"\n\t\t++position;\n\n\t\twhile (isHTTPWhitespaceChar(input[position])) {\n\t\t\t++position;\n\t\t}\n\n\t\tlet parameterName = '';\n\t\twhile (position < input.length && input[position] !== ';' && input[position] !== '=') {\n\t\t\tparameterName += input[position];\n\t\t\t++position;\n\t\t}\n\t\tparameterName = asciiLowercase(parameterName);\n\n\t\tif (position < input.length) {\n\t\t\tif (input[position] === ';') {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Skip past \"=\"\n\t\t\t++position;\n\t\t}\n\n\t\tlet parameterValue = null;\n\t\tif (input[position] === '\"') {\n\t\t\t[parameterValue, position] = collectAnHTTPQuotedString(input, position);\n\n\t\t\twhile (position < input.length && input[position] !== ';') {\n\t\t\t\t++position;\n\t\t\t}\n\t\t} else {\n\t\t\tparameterValue = '';\n\t\t\twhile (position < input.length && input[position] !== ';') {\n\t\t\t\tparameterValue += input[position];\n\t\t\t\t++position;\n\t\t\t}\n\n\t\t\tparameterValue = removeTrailingHTTPWhitespace(parameterValue);\n\n\t\t\tif (parameterValue === '') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (parameterName.length > 0 &&\n\t\t\tsolelyContainsHTTPTokenCodePoints(parameterName) &&\n\t\t\tsolelyContainsHTTPQuotedStringTokenCodePoints(parameterValue) &&\n\t\t\t!mediaType.parameters.has(parameterName)) {\n\t\t\tmediaType.parameters.set(parameterName, parameterValue);\n\t\t}\n\t}\n\n\treturn mediaType;\n};\n\nexport default parse;", "import { solelyContainsHTTPTokenCodePoints } from './utils.js';\n// eslint-disable-next-line jsdoc/valid-types\n/** @typedef { import('./media-type.js').default } MediaType */\n\n/**\n * A function that serializes the provided {@link mediaType} to a string.\n *\n * @module serializer\n * @param {MediaType} mediaType The media type to serialize.\n * @returns {string} The serialized media type.\n */\nconst serialize = (mediaType) => {\n\tlet serialization = `${mediaType.type}/${mediaType.subtype}`;\n\n\tif (mediaType.parameters.size === 0) {\n\t\treturn serialization;\n\t}\n\n\tfor (let [name, value] of mediaType.parameters) {\n\t\tserialization += ';';\n\t\tserialization += name;\n\t\tserialization += '=';\n\n\t\tif (!solelyContainsHTTPTokenCodePoints(value) || value.length === 0) {\n\t\t\tvalue = value.replace(/([\"\\\\])/ug, '\\\\$1');\n\t\t\tvalue = `\"${value}\"`;\n\t\t}\n\n\t\tserialization += value;\n\t}\n\n\treturn serialization;\n};\n\nexport default serialize;"],
5
- "mappings": "gbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,ICQA,IAAMC,EAA0CC,GAAWA,EAAO,QAAQ,eAAgB,EAAE,EAAE,QAAQ,eAAgB,EAAE,EAQlHC,EAAgCD,GAAWA,EAAO,QAAQ,eAAgB,EAAE,EAQ5EE,EAAwBC,GAASA,IAAS,KAAOA,IAAS,KAAQA,IAAS;AAAA,GAAQA,IAAS,KAQ5FC,EAAqCJ,GAAW,iCAAiC,KAAKA,CAAM,EAQ5FK,EAAiDL,GAAW,qCAAqC,KAAKA,CAAM,EAQ5GM,EAAkBN,GAAWA,EAAO,QAAQ,UAAWO,GAAKA,EAAE,YAAY,CAAC,EAU3EC,EAA4B,CAACC,EAAOC,IAAa,CACtD,IAAIC,EAAQ,GAIZ,IAFAD,MAEa,CACZ,KAAOA,EAAWD,EAAM,QAAUA,EAAMC,KAAc,KAAOD,EAAMC,KAAc,MAChFC,GAASF,EAAMC,GACf,EAAEA,EAGH,GAAIA,GAAYD,EAAM,OACrB,MAGD,IAAMG,EAAmBH,EAAMC,GAG/B,GAFA,EAAEA,EAEEE,IAAqB,KAAM,CAC9B,GAAIF,GAAYD,EAAM,OAAQ,CAC7BE,GAAS,KACT,KACD,CAEAA,GAASF,EAAM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,IAAI,MAAM,6CAA6C,EAE9D,GAAI,CAACE,EAAkCF,CAAK,EAC3C,MAAM,IAAI,MAAM,mBAAmBA,6CAAiD,EAGrF,KAAK,SAAWA,CACjB,CAOA,IAAI,YAAa,CAChB,OAAO,KAAK,WACb,CAOA,UAAW,CAGV,OAAOG,EAAU,IAAI,CACtB,CASA,aAAa,CAAC,mBAAAC,EAAqB,EAAK,EAAI,CAAC,EAAG,CAC/C,OAAQ,KAAK,MAAO,CACnB,IAAK,OACJ,OAAQ,KAAK,SAAU,CACtB,IAAK,aACL,IAAK,aACL,IAAK,gBACL,IAAK,gBACL,IAAK,gBACL,IAAK,gBACL,IAAK,gBACL,IAAK,gBACL,IAAK,UACL,IAAK,aACL,IAAK,eACL,IAAK,eAAgB,MAAO,CAACA,GAAsB,KAAK,YAAY,OAAS,EAC7E,QAAS,MAAO,EACjB,CAED,IAAK,cACJ,OAAQ,KAAK,SAAU,CACtB,IAAK,aACL,IAAK,aACL,IAAK,eACL,IAAK,eAAgB,MAAO,CAACA,GAAsB,KAAK,YAAY,OAAS,EAC7E,QAAS,MAAO,EACjB,CAED,QAAS,MAAO,EACjB,CACD,CAOA,OAAQ,CACP,OAAQ,KAAK,WAAa,QAAU,KAAK,QAAU,QAAU,KAAK,QAAU,gBAAmB,KAAK,SAAS,SAAS,MAAM,CAC7H,CAOA,QAAS,CACR,OAAO,KAAK,WAAa,QAAU,KAAK,QAAU,MACnD,CAOA,IAAK,OAAO,cAAe,CAC1B,MAAO,WACR,CACD",
4
+ "sourcesContent": ["import MediaTypeParameters from './media-type-parameters.js';\nimport parse from './parser.js';\nimport serialize from './serializer.js';\nimport { asciiLowercase, solelyContainsHTTPTokenCodePoints } from './utils.js';\n\n/**\n * Class used to parse media types.\n *\n * @see https://mimesniff.spec.whatwg.org/#understanding-mime-types\n * @module MediaType\n */\nexport default class MediaType {\n\t/**\n\t * Create a new MediaType instance from a string representation.\n\t *\n\t * @param {string} string The media type to parse\n\t */\n\tconstructor(string) {\n\t\tstring = String(string);\n\t\tconst result = parse(string);\n\t\tif (result === null) {\n\t\t\tthrow new Error(`Could not parse media type string '${string}'`);\n\t\t}\n\n\t\tthis._type = result.type;\n\t\tthis._subtype = result.subtype;\n\t\tthis._parameters = new MediaTypeParameters(result.parameters);\n\t}\n\n\t/**\n\t * Static factor method for parsing a media type.\n\t *\n\t * @param {string} string The media type to parse\n\t * @returns {MediaType} The parsed {@link MediaType} object\n\t */\n\tstatic parse(string) {\n\t\ttry {\n\t\t\treturn new this(string);\n\t\t} catch (e) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Gets the media type essence (type/subtype).\n\t *\n\t * @returns {string} The media type without any parameters\n\t */\n\tget essence() {\n\t\treturn `${this.type}/${this.subtype}`;\n\t}\n\n\t/**\n\t * Gets the type.\n\t *\n\t * @returns {string} The type.\n\t */\n\tget type() {\n\t\treturn this._type;\n\t}\n\n\t/**\n\t * Sets the type.\n\t */\n\tset type(value) {\n\t\tvalue = asciiLowercase(String(value));\n\n\t\tif (value.length === 0) {\n\t\t\tthrow new Error('Invalid type: must be a non-empty string');\n\t\t}\n\t\tif (!solelyContainsHTTPTokenCodePoints(value)) {\n\t\t\tthrow new Error(`Invalid type ${value}: must contain only HTTP token code points`);\n\t\t}\n\n\t\tthis._type = value;\n\t}\n\n\t/**\n\t * Gets the subtype.\n\t *\n\t * @returns {string} The subtype.\n\t */\n\tget subtype() {\n\t\treturn this._subtype;\n\t}\n\n\t/**\n\t * Sets the subtype.\n\t */\n\tset subtype(value) {\n\t\tvalue = asciiLowercase(String(value));\n\n\t\tif (value.length === 0) {\n\t\t\tthrow new Error('Invalid subtype: must be a non-empty string');\n\t\t}\n\t\tif (!solelyContainsHTTPTokenCodePoints(value)) {\n\t\t\tthrow new Error(`Invalid subtype ${value}: must contain only HTTP token code points`);\n\t\t}\n\n\t\tthis._subtype = value;\n\t}\n\n\t/**\n\t * Gets the parameters.\n\t *\n\t * @returns {MediaTypeParameters} The media type parameters.\n\t */\n\tget parameters() {\n\t\treturn this._parameters;\n\t}\n\n\t/**\n\t * Gets the serialized version of the media type.\n\t *\n\t * @returns {string} The serialized media type.\n\t */\n\ttoString() {\n\t\t// The serialize function works on both 'media type records' (i.e. the results of parse) and on this class, since\n\t\t// this class's interface is identical.\n\t\treturn serialize(this);\n\t}\n\n\t/**\n\t * Determines if this instance is a JavaScript media type.\n\t *\n\t * @param {Object} [options] Optional options.\n\t * @param {boolean} [options.prohibitParameters=false] The option to prohibit parameters when checking if the media type is JavaScript.\n\t * @returns {boolean} true if this instance represents a JavaScript media type, false otherwise.\n\t */\n\tisJavaScript({prohibitParameters = false} = {}) {\n\t\tswitch (this._type) {\n\t\t\tcase 'text': {\n\t\t\t\tswitch (this._subtype) {\n\t\t\t\t\tcase 'ecmascript':\n\t\t\t\t\tcase 'javascript':\n\t\t\t\t\tcase 'javascript1.0':\n\t\t\t\t\tcase 'javascript1.1':\n\t\t\t\t\tcase 'javascript1.2':\n\t\t\t\t\tcase 'javascript1.3':\n\t\t\t\t\tcase 'javascript1.4':\n\t\t\t\t\tcase 'javascript1.5':\n\t\t\t\t\tcase 'jscript':\n\t\t\t\t\tcase 'livescript':\n\t\t\t\t\tcase 'x-ecmascript':\n\t\t\t\t\tcase 'x-javascript': return !prohibitParameters || this._parameters.size === 0;\n\t\t\t\t\tdefault: return false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcase 'application': {\n\t\t\t\tswitch (this._subtype) {\n\t\t\t\t\tcase 'ecmascript':\n\t\t\t\t\tcase 'javascript':\n\t\t\t\t\tcase 'x-ecmascript':\n\t\t\t\t\tcase 'x-javascript': return !prohibitParameters || this._parameters.size === 0;\n\t\t\t\t\tdefault: return false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdefault: return false;\n\t\t}\n\t}\n\n\t/**\n\t * Determines if this instance is an XML media type.\n\t *\n\t * @returns {boolean} true if this instance represents an XML media type, false otherwise.\n\t */\n\tisXML() {\n\t\treturn (this._subtype === 'xml' && (this._type === 'text' || this._type === 'application')) || this._subtype.endsWith('+xml');\n\t}\n\n\t/**\n\t * Determines if this instance is an HTML media type.\n\t *\n\t * @returns {boolean} true if this instance represents an HTML media type, false otherwise.\n\t */\n\tisHTML() {\n\t\treturn this._subtype === 'html' && this._type === 'text';\n\t}\n\n\t/**\n\t * Gets the name of the class.\n\t *\n\t * @returns {string} The class name\n\t */\n\tget [Symbol.toStringTag]() {\n\t\treturn 'MediaType';\n\t}\n}", "/** @module utils */\n\n/**\n * A function to remove any leading and trailing HTTP whitespace.\n *\n * @param {string} string The string to process.\n * @returns {string} The processed string.\n */\nconst removeLeadingAndTrailingHTTPWhitespace = (string) => string.replace(/^[ \\t\\n\\r]+/u, '').replace(/[ \\t\\n\\r]+$/u, '');\n\n/**\n * A function to remove any trailing HTTP whitespace.\n *\n * @param {string} string The string to process.\n * @returns {string} The processed string.\n */\nconst removeTrailingHTTPWhitespace = (string) => string.replace(/[ \\t\\n\\r]+$/u, '');\n\n/**\n * Determines if the provided character is whitespace.\n *\n * @param {string} char The character to evaluate.\n * @returns {boolean} true if the character is whitespace, false otherwise.\n */\nconst isHTTPWhitespaceChar = (char) => char === ' ' || char === '\\t' || char === '\\n' || char === '\\r';\n\n/**\n * Determines if the provided string contains only HTTP token code points.\n *\n * @param {string} string The string to evaluate.\n * @returns {boolean} true if the string contains only HTTP token code points.\n */\nconst solelyContainsHTTPTokenCodePoints = (string) => /^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u.test(string);\n\n/**\n * Determines if the provided string contains only quoted HTTP token code points.\n *\n * @param {string} string The string to evaluate.\n * @returns {boolean} true if the string contains only quoted HTTP token code points.\n */\nconst solelyContainsHTTPQuotedStringTokenCodePoints = (string) => /^[\\t\\u0020-\\u007E\\u0080-\\u00FF]*$/u.test(string);\n\n/**\n * A function to lower case ASCII characters.\n *\n * @param {string} string The string to process.\n * @returns {string} The processed string with all ASCII characters lower cased.\n */\nconst asciiLowercase = (string) => string.replace(/[A-Z]/ug, l => l.toLowerCase());\n\n/**\n * Collects all the HTTP quoted strings.\n * This variant only implements it with the extract-value flag set.\n *\n * @param {string} input The string to process.\n * @param {number} position The starting position.\n * @returns {Array<string | number>} An array that includes the resulting string and updated position.\n */\nconst collectAnHTTPQuotedString = (input, position) => {\n\tlet value = '';\n\n\tposition++;\n\n\twhile (true) {\n\t\twhile (position < input.length && input[position] !== '\"' && input[position] !== '\\\\') {\n\t\t\tvalue += input[position];\n\t\t\t++position;\n\t\t}\n\n\t\tif (position >= input.length) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst quoteOrBackslash = input[position];\n\t\t++position;\n\n\t\tif (quoteOrBackslash === '\\\\') {\n\t\t\tif (position >= input.length) {\n\t\t\t\tvalue += '\\\\';\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tvalue += input[position];\n\t\t\t++position;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn [value, position];\n};\n\nexport { removeLeadingAndTrailingHTTPWhitespace, removeTrailingHTTPWhitespace, isHTTPWhitespaceChar, solelyContainsHTTPTokenCodePoints, solelyContainsHTTPQuotedStringTokenCodePoints, asciiLowercase, collectAnHTTPQuotedString };\n", "import { asciiLowercase, solelyContainsHTTPQuotedStringTokenCodePoints, solelyContainsHTTPTokenCodePoints } from './utils.js';\n\n/**\n * Class representing the parameters for a media type record.\n * This class has the equivalent surface API to a JavaScript {@link Map}.\n *\n * However, {@link 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 {@link Error}.\n *\n * @example charset=utf-8\n * @module MediaTypeParameters\n */\nexport default class MediaTypeParameters {\n\t/**\n\t * Create a new MediaTypeParameters instance.\n\t *\n\t * @param {Map.<string, string>} map The map of parameters for a media type.\n\t */\n\tconstructor(map) {\n\t\tthis._map = map;\n\t}\n\n\t/**\n\t * Gets the number of media type parameters.\n\t *\n\t * @returns {number} The number of media type parameters\n\t */\n\tget size() {\n\t\treturn this._map.size;\n\t}\n\n\t/**\n\t * Gets the media type parameter value for the supplied name.\n\t *\n\t * @param {string} name The name of the media type parameter to retrieve.\n\t * @returns {string} The media type parameter value.\n\t */\n\tget(name) {\n\t\treturn this._map.get(asciiLowercase(String(name)));\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 {string} name The name of the media type parameter to check.\n\t * @returns {boolean} true if the media type parameter exists, false otherwise.\n\t */\n\thas(name) {\n\t\treturn this._map.has(asciiLowercase(String(name)));\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 {string} name The name of the media type parameter to set.\n\t * @param {string} value The media type parameter value.\n\t * @returns {MediaTypeParameters} This instance.\n\t */\n\tset(name, value) {\n\t\tname = asciiLowercase(String(name));\n\t\tvalue = String(value);\n\n\t\tif (!solelyContainsHTTPTokenCodePoints(name)) {\n\t\t\tthrow new Error(`Invalid media type parameter name \"${name}\": only HTTP token code points are valid.`);\n\t\t}\n\n\t\tif (!solelyContainsHTTPQuotedStringTokenCodePoints(value)) {\n\t\t\tthrow new Error(`Invalid media type parameter value \"${value}\": only HTTP quoted-string token code points are valid.`);\n\t\t}\n\n\t\tthis._map.set(name, value);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Clears all the media type parameters.\n\t */\n\tclear() {\n\t\tthis._map.clear();\n\t}\n\n\t/**\n\t * Removes the media type parameter using the specified name.\n\t *\n\t * @param {string} name The name of the media type parameter to delete.\n\t * @returns {boolean} true if the parameter existed and has been removed, or false if the parameter does not exist.\n\t */\n\tdelete(name) {\n\t\tname = asciiLowercase(String(name));\n\t\treturn this._map.delete(name);\n\t}\n\n\t/**\n\t * Executes a provided function once per each name/value pair in the MediaTypeParameters, in insertion order.\n\t *\n\t * @param {function(string, string): void} callback The function called on each iteration.\n\t * @param {*} [thisArg] Optional object when binding 'this' to the callback.\n\t */\n\tforEach(callback, thisArg) {\n\t\tthis._map.forEach(callback, thisArg);\n\t}\n\n\t/**\n\t * Returns an iterable of parameter names.\n\t *\n\t * @returns {IterableIterator<string>} The {@link IterableIterator} of media type parameter names.\n\t */\n\tkeys() {\n\t\treturn this._map.keys();\n\t}\n\n\t/**\n\t * Returns an iterable of parameter values.\n\t *\n\t * @returns {IterableIterator<string>} The {@link IterableIterator} of media type parameter values.\n\t */\n\tvalues() {\n\t\treturn this._map.values();\n\t}\n\n\t/**\n\t * Returns an iterable of name, value pairs for every parameter entry in the media type parameters.\n\t *\n\t * @returns {IterableIterator<Array<Array<string>>>} The media type parameter entries.\n\t */\n\tentries() {\n\t\treturn this._map.entries();\n\t}\n\n\t/**\n\t * A method that returns the default iterator for the {@link MediaTypeParameters}. Called by the semantics of the for-of statement.\n\t *\n\t * @returns {Iterator<string, string, undefined>} The {@link Symbol.iterator} for the media type parameters.\n\t */\n\t[Symbol.iterator]() {\n\t\treturn this._map[Symbol.iterator]();\n\t}\n}", "import {\n\tasciiLowercase,\n\tcollectAnHTTPQuotedString, isHTTPWhitespaceChar, removeLeadingAndTrailingHTTPWhitespace,\n\tremoveTrailingHTTPWhitespace, solelyContainsHTTPQuotedStringTokenCodePoints, solelyContainsHTTPTokenCodePoints\n} from './utils.js';\n\n/**\n * Function to parse a media type.\n *\n * @module parser\n * @param {string} input The media type to parse\n * @returns {{ type: string, subtype: string, parameters: Map<string, string> }} An object populated with the parsed media type properties and any parameters.\n */\nconst parse = (input) => {\n\tinput = removeLeadingAndTrailingHTTPWhitespace(input);\n\n\tlet position = 0;\n\tlet type = '';\n\twhile (position < input.length && input[position] !== '/') {\n\t\ttype += input[position];\n\t\t++position;\n\t}\n\n\tif (type.length === 0 || !solelyContainsHTTPTokenCodePoints(type)) {\n\t\treturn null;\n\t}\n\n\tif (position >= input.length) {\n\t\treturn null;\n\t}\n\n\t// Skips past \"/\"\n\t++position;\n\n\tlet subtype = '';\n\twhile (position < input.length && input[position] !== ';') {\n\t\tsubtype += input[position];\n\t\t++position;\n\t}\n\n\tsubtype = removeTrailingHTTPWhitespace(subtype);\n\n\tif (subtype.length === 0 || !solelyContainsHTTPTokenCodePoints(subtype)) {\n\t\treturn null;\n\t}\n\n\tconst mediaType = {\n\t\ttype: asciiLowercase(type),\n\t\tsubtype: asciiLowercase(subtype),\n\t\tparameters: new Map()\n\t};\n\n\twhile (position < input.length) {\n\t\t// Skip past \";\"\n\t\t++position;\n\n\t\twhile (isHTTPWhitespaceChar(input[position])) {\n\t\t\t++position;\n\t\t}\n\n\t\tlet parameterName = '';\n\t\twhile (position < input.length && input[position] !== ';' && input[position] !== '=') {\n\t\t\tparameterName += input[position];\n\t\t\t++position;\n\t\t}\n\t\tparameterName = asciiLowercase(parameterName);\n\n\t\tif (position < input.length) {\n\t\t\tif (input[position] === ';') {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Skip past \"=\"\n\t\t\t++position;\n\t\t}\n\n\t\tlet parameterValue = null;\n\t\tif (input[position] === '\"') {\n\t\t\t[parameterValue, position] = collectAnHTTPQuotedString(input, position);\n\n\t\t\twhile (position < input.length && input[position] !== ';') {\n\t\t\t\t++position;\n\t\t\t}\n\t\t} else {\n\t\t\tparameterValue = '';\n\t\t\twhile (position < input.length && input[position] !== ';') {\n\t\t\t\tparameterValue += input[position];\n\t\t\t\t++position;\n\t\t\t}\n\n\t\t\tparameterValue = removeTrailingHTTPWhitespace(parameterValue);\n\n\t\t\tif (parameterValue === '') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (parameterName.length > 0 &&\n\t\t\tsolelyContainsHTTPTokenCodePoints(parameterName) &&\n\t\t\tsolelyContainsHTTPQuotedStringTokenCodePoints(parameterValue) &&\n\t\t\t!mediaType.parameters.has(parameterName)) {\n\t\t\tmediaType.parameters.set(parameterName, parameterValue);\n\t\t}\n\t}\n\n\treturn mediaType;\n};\n\nexport default parse;", "import { solelyContainsHTTPTokenCodePoints } from './utils.js';\n// eslint-disable-next-line jsdoc/valid-types\n/** @typedef { import('./media-type.js').default } MediaType */\n\n/**\n * A function that serializes the provided {@link mediaType} to a string.\n *\n * @module serializer\n * @param {MediaType} mediaType The media type to serialize.\n * @returns {string} The serialized media type.\n */\nconst serialize = (mediaType) => {\n\tlet serialization = `${mediaType.type}/${mediaType.subtype}`;\n\n\tif (mediaType.parameters.size === 0) {\n\t\treturn serialization;\n\t}\n\n\tfor (let [name, value] of mediaType.parameters) {\n\t\tserialization += ';';\n\t\tserialization += name;\n\t\tserialization += '=';\n\n\t\tif (!solelyContainsHTTPTokenCodePoints(value) || value.length === 0) {\n\t\t\tvalue = value.replace(/([\"\\\\])/ug, '\\\\$1');\n\t\t\tvalue = `\"${value}\"`;\n\t\t}\n\n\t\tserialization += value;\n\t}\n\n\treturn serialization;\n};\n\nexport default serialize;"],
5
+ "mappings": "gbAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,ICQA,IAAMC,EAA0CC,GAAWA,EAAO,QAAQ,eAAgB,EAAE,EAAE,QAAQ,eAAgB,EAAE,EAQlHC,EAAgCD,GAAWA,EAAO,QAAQ,eAAgB,EAAE,EAQ5EE,EAAwBC,GAASA,IAAS,KAAOA,IAAS,KAAQA,IAAS;AAAA,GAAQA,IAAS,KAQ5FC,EAAqCJ,GAAW,iCAAiC,KAAKA,CAAM,EAQ5FK,EAAiDL,GAAW,qCAAqC,KAAKA,CAAM,EAQ5GM,EAAkBN,GAAWA,EAAO,QAAQ,UAAWO,GAAKA,EAAE,YAAY,CAAC,EAU3EC,EAA4B,CAACC,EAAOC,IAAa,CACtD,IAAIC,EAAQ,GAIZ,IAFAD,MAEa,CACZ,KAAOA,EAAWD,EAAM,QAAUA,EAAMC,KAAc,KAAOD,EAAMC,KAAc,MAChFC,GAASF,EAAMC,GACf,EAAEA,EAGH,GAAIA,GAAYD,EAAM,OACrB,MAGD,IAAMG,EAAmBH,EAAMC,GAG/B,GAFA,EAAEA,EAEEE,IAAqB,KAAM,CAC9B,GAAIF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EAAQC,EAAe,OAAOD,CAAK,CAAC,EAEhCA,EAAM,SAAW,EACpB,MAAM,IAAI,MAAM,6CAA6C,EAE9D,GAAI,CAACE,EAAkCF,CAAK,EAC3C,MAAM,IAAI,MAAM,mBAAmBA,6CAAiD,EAGrF,KAAK,SAAWA,CACjB,CAOA,IAAI,YAAa,CAChB,OAAO,KAAK,WACb,CAOA,UAAW,CAGV,OAAOG,EAAU,IAAI,CACtB,CASA,aAAa,CAAC,mBAAAC,EAAqB,EAAK,EAAI,CAAC,EAAG,CAC/C,OAAQ,KAAK,MAAO,CACnB,IAAK,OACJ,OAAQ,KAAK,SAAU,CACtB,IAAK,aACL,IAAK,aACL,IAAK,gBACL,IAAK,gBACL,IAAK,gBACL,IAAK,gBACL,IAAK,gBACL,IAAK,gBACL,IAAK,UACL,IAAK,aACL,IAAK,eACL,IAAK,eAAgB,MAAO,CAACA,GAAsB,KAAK,YAAY,OAAS,EAC7E,QAAS,MAAO,EACjB,CAED,IAAK,cACJ,OAAQ,KAAK,SAAU,CACtB,IAAK,aACL,IAAK,aACL,IAAK,eACL,IAAK,eAAgB,MAAO,CAACA,GAAsB,KAAK,YAAY,OAAS,EAC7E,QAAS,MAAO,EACjB,CAED,QAAS,MAAO,EACjB,CACD,CAOA,OAAQ,CACP,OAAQ,KAAK,WAAa,QAAU,KAAK,QAAU,QAAU,KAAK,QAAU,gBAAmB,KAAK,SAAS,SAAS,MAAM,CAC7H,CAOA,QAAS,CACR,OAAO,KAAK,WAAa,QAAU,KAAK,QAAU,MACnD,CAOA,IAAK,OAAO,cAAe,CAC1B,MAAO,WACR,CACD",
6
6
  "names": ["media_type_exports", "__export", "MediaType", "removeLeadingAndTrailingHTTPWhitespace", "string", "removeTrailingHTTPWhitespace", "isHTTPWhitespaceChar", "char", "solelyContainsHTTPTokenCodePoints", "solelyContainsHTTPQuotedStringTokenCodePoints", "asciiLowercase", "l", "collectAnHTTPQuotedString", "input", "position", "value", "quoteOrBackslash", "MediaTypeParameters", "map", "name", "asciiLowercase", "value", "solelyContainsHTTPTokenCodePoints", "solelyContainsHTTPQuotedStringTokenCodePoints", "callback", "thisArg", "parse", "input", "removeLeadingAndTrailingHTTPWhitespace", "position", "type", "solelyContainsHTTPTokenCodePoints", "subtype", "removeTrailingHTTPWhitespace", "mediaType", "asciiLowercase", "isHTTPWhitespaceChar", "parameterName", "parameterValue", "collectAnHTTPQuotedString", "solelyContainsHTTPQuotedStringTokenCodePoints", "parser_default", "serialize", "mediaType", "serialization", "name", "value", "solelyContainsHTTPTokenCodePoints", "serializer_default", "MediaType", "string", "result", "parser_default", "MediaTypeParameters", "value", "asciiLowercase", "solelyContainsHTTPTokenCodePoints", "serializer_default", "prohibitParameters"]
7
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": "4.0.0",
4
+ "version": "4.0.1",
5
5
  "author": "Domenic Denicola <d@domenic.me> (https://domenic.me/)",
6
6
  "maintainers": [
7
7
  {
@@ -53,12 +53,12 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@skypack/package-check": "^0.2.2",
56
- "esbuild": "^0.15.10",
56
+ "esbuild": "^0.15.12",
57
57
  "eslint": "^8.25.0",
58
58
  "eslint-plugin-compat": "^4.0.2",
59
- "eslint-plugin-jsdoc": "^39.3.6",
60
- "jest": "^29.1.2",
61
- "minipass-fetch": "^2.1.2",
59
+ "eslint-plugin-jsdoc": "^39.3.14",
60
+ "jest": "^29.2.1",
61
+ "minipass-fetch": "^3.0.0",
62
62
  "printable-string": "^0.3.0",
63
63
  "rimraf": "^3.0.2",
64
64
  "whatwg-encoding": "^2.0.0"