wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.build = build;
function isQuoted(val) {
    if (val[0] !== '{') {
        return false;
    }
    for (let i = 1; i < val.length; i++) {
        if (val[i] === '}') {
            if (i + 1 === val.length) {
                // if last char, then it's quoted properly
                return true;
            }
            else if (val[i + 1] !== '}') {
                // the next char is no a `}` so there is no valid escaping here
                return false;
            }
            else {
                // we are seeing an escaped `}`, so skip ahead
                i++;
            }
        }
    }
    return false;
}
function needsQuotes(val) {
    return !isQuoted(val) && !!val.match(/\[|]|{|}|\|\(|\)|,|;|\?|\*|=|!|@/)?.length;
}
function encodeTuple(key, value) {
    if (value === null || value === undefined) {
        return [key, ''];
    }
    switch (typeof value) {
        case 'boolean':
            return [key, value ? 'Yes' : 'No'];
        default: {
            const strVal = value.toString();
            if (needsQuotes(strVal)) {
                return [key, `{${strVal.replace(/}/g, '}}')}}`];
            }
            return [key, strVal];
        }
    }
}
function build(data) {
    return Object.entries(data).map(([key, value]) => {
        return encodeTuple(key.trim(), value).join('=');
    }).join(';');
}
//# sourceMappingURL=index.js.map