"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvMap = void 0;
const normalizeKey = (key) => process.platform === 'win32' ? key.toUpperCase() : key;
const set = (map, key, value) => {
    const existingKey = map.get(normalizeKey(key))?.[0];
    map.set(normalizeKey(key), [existingKey ?? key, value]);
};
/**
 * On Windows this behaves as a case-insensitive, case-preserving map.
 * On other platforms this is analog to Map<string, string | undefined>
 */
class EnvMap {
    map = new Map();
    get size() {
        return this.map.size;
    }
    constructor(iterable) {
        if (iterable) {
            for (const [k, v] of iterable) {
                set(this.map, k, v);
            }
        }
    }
    [Symbol.iterator]() {
        return this.entries();
    }
    get [Symbol.toStringTag]() {
        return 'EnvMap';
    }
    entries() {
        return this.map.values();
    }
    *keys() {
        for (const [k] of this.map.values()) {
            yield k;
        }
    }
    *values() {
        for (const [, v] of this.map.values()) {
            yield v;
        }
    }
    get(key) {
        return this.map.get(normalizeKey(key))?.[1];
    }
    set(key, value) {
        set(this.map, key, value);
        return this;
    }
    has(key) {
        return this.map.has(normalizeKey(key));
    }
    clear() {
        this.map.clear();
    }
    forEach(callbackFn, thisArg) {
        this.map.forEach(([k, v]) => callbackFn.call(thisArg, v, k, this));
    }
    delete(key) {
        return this.map.delete(normalizeKey(key));
    }
}
exports.EnvMap = EnvMap;
//# sourceMappingURL=env-map.js.map