Open saranli opened 3 years ago
GPT-4 suggests the following, for whatever this is worth:
// -----------------------------------------------------------------------------
// Extend a destination object with properties from a source object, optionally
// overwriting existing elements.
// @param {object} fr Source object
// @param {object} to Destination object
// @param {boolean} ow Whether to overwrite existing properties of destination
function extendo(to, fr, ow) {
let prop, hasProp;
for (prop in fr) {
if (fr.hasOwnProperty(prop)) { // Ensure prop comes from the source object
hasProp = to[prop] !== undefined;
if (typeof fr[prop] === 'object' && fr[prop] !== null &&
fr[prop].nodeName === undefined) {
if (Array.isArray(fr[prop])) {
to[prop] = fr[prop].map(item => {
if (typeof item === 'object' && item !== null) {
return extendo(Array.isArray(item) ? [] : {}, item, ow);
}
return item
})
} else {
to[prop] = extendo({}, fr[prop], ow)
}
} else if (ow || !hasProp) {
to[prop] = fr[prop]
}
}
}
return to
}
Default options for bgraph has inner objects to specify various suboptions. However, if an option is specified externally, inner objects are directly replaced, and if the external specification does not include all of the required parameters, bgraph will exit with errors. The solution is to go through the external options and replace provided values in inner objects as well.
Copy of the function in question for reference:
Verbata: refactor, refactoring, robustness, javascript idiosyncrasies,