in settings/settings.js [91:127]
async setAsync(settingPath, value) {
if (this.readonly) {
throw new Error("Readonly settings cannot be modified.");
}
if (!settingPath || !utils.isString(settingPath)) {
throw new Error(`Invalid setting path: ${settingPath}`);
}
/** @type {Array.<string>} */
const pathParts = settingPath.split("/");
/** @type {*} */
let settingValue = this.settings;
for (let pathPartIndex = 0; pathPartIndex < pathParts.length; pathPartIndex++) {
if (settingValue === null || (!Array.isArray(settingValue) && !utils.isObject(settingValue))) {
throw new Error("Unable to travel the settings path because the settings type is not array or object or it is null.");
}
const pathPart = pathParts[pathPartIndex];
if (pathPartIndex === pathParts.length - 1) {
if (value === undefined) {
delete settingValue[pathPart];
} else {
settingValue[pathPart] = value;
}
} else if (settingValue[pathPart] === undefined) {
settingValue[pathPart] = Object.create(null);
}
settingValue = settingValue[pathPart];
}
}