function graftPLIST()

in src/util/plist-helpers.js [26:45]


function graftPLIST (doc, xml, selector) {
    const obj = plist.parse(`<plist>${xml}</plist>`);
    const node = doc[selector];

    if (node && Array.isArray(node) && Array.isArray(obj)) {
        const isNew = item => !node.some(nodeChild => nodeEqual(item, nodeChild));
        doc[selector] = node.concat(obj.filter(isNew));
    } else {
        // plist uses objects for <dict>. If we have two dicts we merge them instead of
        // overriding the old one. See CB-6472
        const isDict = o => typeof o === 'object' && !util.types.isDate(o); // arrays checked above
        if (isDict(node) && isDict(obj)) {
            Object.assign(obj, node);
        }

        doc[selector] = obj;
    }

    return true;
}