@http4t/core
Advanced tools
Comparing version 0.0.104 to 0.0.105
import { Header, HeaderName, HeaderValue } from './contract'; | ||
/** | ||
* Case insensitive on name | ||
*/ | ||
export declare function getHeaderValue(headers: Header[], name: HeaderName): HeaderValue | undefined; | ||
@@ -3,0 +6,0 @@ export declare type HeaderValueLike = string | number | Date; |
@@ -31,2 +31,5 @@ "use strict"; | ||
// TODO: clean up this gross namespace | ||
/** | ||
* Case insensitive on name | ||
*/ | ||
function getHeaderValue(headers, name) { | ||
@@ -33,0 +36,0 @@ var e_1, _a; |
@@ -6,2 +6,5 @@ import {Header, HeaderName, HeaderValue} from './contract'; | ||
/** | ||
* Case insensitive on name | ||
*/ | ||
export function getHeaderValue(headers: Header[], name: HeaderName): HeaderValue | undefined { | ||
@@ -8,0 +11,0 @@ if(!headers) |
19
json.js
@@ -58,3 +58,3 @@ "use strict"; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, __await(JSON.stringify(data))]; | ||
case 0: return [4 /*yield*/, __await(typeof data === 'undefined' ? "" : JSON.stringify(data))]; | ||
case 1: return [4 /*yield*/, _a.sent()]; | ||
@@ -100,5 +100,5 @@ case 2: | ||
return __awaiter(this, void 0, void 0, function () { | ||
var body, _a, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
var body, text; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
@@ -108,5 +108,8 @@ body = contract_1.isMessage(value) ? value.body : value; | ||
return [2 /*return*/, body.data]; | ||
_b = (_a = JSON).parse; | ||
return [4 /*yield*/, bodies_1.bufferText(body)]; | ||
case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])]; | ||
case 1: | ||
text = _a.sent(); | ||
if (text === "") | ||
return [2 /*return*/, undefined]; | ||
return [2 /*return*/, JSON.parse(text)]; | ||
} | ||
@@ -125,6 +128,8 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var parsed; | ||
return __generator(this, function (_a) { | ||
if (message.body instanceof JsonBody) | ||
return [2 /*return*/, message]; | ||
return [2 /*return*/, objects_1.modify(message, { body: jsonBody(bodyJson(message.body)) })]; | ||
parsed = bodyJson(message.body); | ||
return [2 /*return*/, objects_1.modify(message, { body: jsonBody(parsed) })]; | ||
}); | ||
@@ -131,0 +136,0 @@ }); |
11
json.ts
@@ -6,3 +6,3 @@ import {bufferText} from "./bodies"; | ||
async function* yieldStringify(data: object): AsyncIterable<Data> { | ||
yield JSON.stringify(data) | ||
yield typeof data ==='undefined' ? "" : JSON.stringify(data) | ||
} | ||
@@ -41,7 +41,9 @@ | ||
*/ | ||
export async function bodyJson<T>(value: Body | HttpMessage): Promise<T> { | ||
export async function bodyJson<T>(value: Body | HttpMessage): Promise<T | undefined> { | ||
const body = isMessage(value) ? value.body : value; | ||
if (body instanceof JsonBody) | ||
return body.data; | ||
return JSON.parse(await bufferText(body)); | ||
const text = await bufferText(body); | ||
if(text === "") return undefined; | ||
return JSON.parse(text); | ||
} | ||
@@ -59,3 +61,4 @@ | ||
return modify(message, {body: jsonBody(bodyJson(message.body))} as any); | ||
const parsed = bodyJson(message.body); | ||
return modify(message, {body: jsonBody(parsed)} as any); | ||
} |
{ | ||
"name": "@http4t/core", | ||
"version": "0.0.104", | ||
"version": "0.0.105", | ||
"license": "Apache-2.0" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
113798
2059