@otterhttp/content-type
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -9,2 +9,4 @@ import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'node:http'; | ||
}; | ||
type TypeParseableObject = Request | Response; | ||
type TypeParseable = string | TypeParseableObject; | ||
/** | ||
@@ -28,5 +30,5 @@ * Class to represent a content type. | ||
*/ | ||
declare function parse(string: string | Request | Response): ContentType; | ||
declare function parse(value: TypeParseable): ContentType; | ||
declare function isPlainText({ type }: ContentType): boolean; | ||
export { format, isPlainText, parse }; | ||
export { type TypeParseable, type TypeParseableObject, format, isPlainText, parse }; |
@@ -19,4 +19,3 @@ // src/index.ts | ||
} else if ("headers" in obj && typeof obj.headers === "object") { | ||
const h = obj.headers; | ||
header = h?.["content-type"]; | ||
header = obj.headers["content-type"]; | ||
} | ||
@@ -48,5 +47,5 @@ if (typeof header !== "string") { | ||
} | ||
function parse(string) { | ||
if (!string) throw new TypeError("argument string is required"); | ||
const header = typeof string === "object" ? getContentType(string) : string; | ||
function parse(value) { | ||
if (!value) throw new TypeError("argument string is required"); | ||
const header = typeof value === "object" ? getContentType(value) : value; | ||
if (typeof header !== "string") throw new TypeError("argument string is required to be a string"); | ||
@@ -60,3 +59,3 @@ let index = header.indexOf(";"); | ||
let match; | ||
let value; | ||
let value2; | ||
PARAM_REGEXP.lastIndex = index; | ||
@@ -67,7 +66,7 @@ while (match = PARAM_REGEXP.exec(header)) { | ||
key = match[1].toLowerCase(); | ||
value = match[2]; | ||
if (value[0] === '"') { | ||
value = value.slice(1, value.length - 1).replace(QESC_REGEXP, "$1"); | ||
value2 = match[2]; | ||
if (value2[0] === '"') { | ||
value2 = value2.slice(1, value2.length - 1).replace(QESC_REGEXP, "$1"); | ||
} | ||
obj.parameters[key] = value; | ||
obj.parameters[key] = value2; | ||
} | ||
@@ -74,0 +73,0 @@ if (index !== header.length) throw new TypeError("invalid parameter format"); |
{ | ||
"name": "@otterhttp/content-type", | ||
"description": "content-type rewrite in TypeScript", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"license": "LGPL-3.0-or-later", | ||
@@ -6,0 +6,0 @@ "homepage": "https://otterhttp.lordfirespeed.dev", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8887
127