mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-12 16:38:28 -04:00
7974887295
- settings.json/session.json now store only values that differ from spec defaults - Machine-specific state moves out of settings.json into session.json - Add dms backup create/restore: tar.gz of ~/.config/DankMaterialShell fixes #3027
31 lines
819 B
JavaScript
31 lines
819 B
JavaScript
.pragma library
|
|
|
|
function stableStringify(value) {
|
|
if (value === null || typeof value !== "object")
|
|
return JSON.stringify(value);
|
|
if (Array.isArray(value))
|
|
return "[" + value.map(stableStringify).join(",") + "]";
|
|
return "{" + Object.keys(value).sort().map(function (k) {
|
|
return JSON.stringify(k) + ":" + stableStringify(value[k]);
|
|
}).join(",") + "}";
|
|
}
|
|
|
|
function isDefault(value, def) {
|
|
return stableStringify(value) === stableStringify(def);
|
|
}
|
|
|
|
function cloneDef(def) {
|
|
if (def === null || typeof def !== "object")
|
|
return def;
|
|
return JSON.parse(JSON.stringify(def));
|
|
}
|
|
|
|
function stripDefaults(obj, SPEC) {
|
|
for (var k in SPEC) {
|
|
if (!(k in obj))
|
|
continue;
|
|
if (isDefault(obj[k], SPEC[k].def))
|
|
delete obj[k];
|
|
}
|
|
}
|