upgrade.db
Version:
Banco de dados simples e leve em JSON para bots Node.js com suporte a tabelas e métodos modernos.
22 lines (18 loc) • 519 B
JavaScript
function validateKey(key) {
if (typeof key !== 'string' || !key.trim()) {
throw new Error('A chave deve ser uma string válida.');
}
}
function deepGet(obj, path) {
return path.split('_').reduce((o, p) => (o ? o[p] : undefined), obj);
}
function deepSet(obj, path, value) {
const keys = path.split('_');
const last = keys.pop();
const target = keys.reduce((o, p) => {
if (!o[p]) o[p] = {};
return o[p];
}, obj);
target[last] = value;
}
module.exports = { validateKey, deepGet, deepSet };