"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * @module fly
 * @private
 */
const querystring_1 = require("querystring");
/**
 * Class representing a fetch response.
 * @hidden
 */
class FormData {
    constructor() {
        this._data = new Map();
    }
    append(name, value) {
        let vals;
        const currentVals = this._data.get(name);
        if (currentVals == undefined) {
            vals = [value];
        }
        else {
            vals = currentVals.concat([value]);
        }
        this._data.set(name, vals);
    }
    delete(name) {
        this._data.delete(name);
    }
    entries() {
        return this._data.entries();
    }
    get(name) {
        const vals = this._data.get(name);
        if (vals == undefined) {
            return null;
        }
        return vals[0];
    }
    getAll(name) {
        const vals = this._data.get(name);
        if (vals == undefined) {
            return [];
        }
        return vals;
    }
    has(name) {
        return this._data.has(name);
    }
    keys() {
        return this._data.keys();
    }
    set(name, value) {
        this._data.set(name, [value]);
    }
    values() {
        // this._data.values() doesn't flatten arrays of arrays
        let that = this;
        return function* () {
            for (let vals of that._data.values()) {
                if (Array.isArray(vals)) {
                    for (let val of vals) {
                        yield val;
                    }
                }
                else {
                    yield vals;
                }
            }
        }();
    }
    toString() {
        const output = [];
        this._data.forEach((value, key) => {
            output.push(querystring_1.stringify({ [`${key}`]: value }));
        });
        return output.join('&');
    }
}
exports.default = FormData;
//# sourceMappingURL=form_data.js.map