summaryrefslogtreecommitdiff
path: root/cli/bench/testdata/npm/hono/dist/utils/body.js
blob: 5deeca1cdb26fae4d7eedb960d3df66db8a18955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseBody = void 0;
const parseBody = async (r) => {
    const contentType = r.headers.get('Content-Type') || '';
    if (contentType.includes('application/json')) {
        let body = {};
        try {
            body = await r.json();
        }
        catch { } // Do nothing
        return body;
    }
    else if (contentType.includes('application/text')) {
        return await r.text();
    }
    else if (contentType.startsWith('text')) {
        return await r.text();
    }
    else if (contentType.includes('form')) {
        const form = {};
        const data = [...(await r.formData())].reduce((acc, cur) => {
            acc[cur[0]] = cur[1];
            return acc;
        }, form);
        return data;
    }
    const arrayBuffer = await r.arrayBuffer();
    return arrayBuffer;
};
exports.parseBody = parseBody;