@signaldb/core
Version:
SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON in
19 lines (18 loc) • 458 B
JavaScript
;
function get(value, path) {
const normalized = path.replaceAll(/\[(\w+)\]/g, ".$1");
if (normalized.includes("..") || normalized.startsWith(".") || normalized.endsWith(".")) {
return;
}
const segments = normalized.split(".");
let current = value;
for (const key of segments) {
if (current == null)
return;
current = current[key];
}
if (current === void 0)
return;
return current;
}
module.exports = get;