String->INI->JSON

by rsm23

JavaScript

function getAllMatches(regex, text) {
    if (regex.constructor !== RegExp) {
        throw new Error('not RegExp');
    }

    var res = [];
    var match = null;

    if (regex.global) {
        while (match = regex.exec(text)) {
            res.push(match);
        }
    } else {
        if (match = regex.exec(text)) {
            res.push(match);
        }
    }

    return res;
}

function isPlainObject(input) {
    return input && !Array.isArray(input) && typeof input === 'object';
}

const merge = (target, source) => {
    // Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
    for (const key of Object.keys(source)) {
        if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
    }

    // Join `target` and modified `source`
    Object.assign(target || {}, source)
    return target
}

var button = {
    "_id": "60b8835fea9c0b06ac4a999a",
    "datecrea": "2021-06-03T09:23:11+02:00",
    "datemodif": "2021-06-08T09:57:28+02:00",
    "entity": "60b87f07ea9c0b06ac4a9991",
    "code": "8d96e350-c43c-11eb-9ef8-b78782e4fe79",
    "datas": {
        "name": "",
        "color": 1,
        "contrast": 3,
        "recto": 2,
        "orientation": 1,
        "quality": 2,
        "showdate": "",
        "enddate": "",
        "autotrigger": "never",
        "account": "",
        "buttonbg": "#00A1E7",
        "iconcolor": "#ffffff",
        "groupes": [],
        "availableon": [],
        "code": "",
        "requirefiles": false,
        "active": "dev",
        "waituntillfinish": false,
        "namefr": "Scan2Me",
        "descriptionfr": "Scan a document on the MFP and send it to your PC anywhere",
        "svg": "<svg class=\"w-12 h-12\" fill=\"#ffffff\" id=\"buttoniconsvg\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 640 512\"><path d=\"M416 368.4v-99.2c0-8.7-1.8-17.2-5.2-25.2L332.5 61.1C324.9 43.4 307.6 32 288.3 32H144c-26.5 0-48 21.5-48...