hyperborea-character-sheet/src/resolvePointer.cjs

14 lines
415 B
JavaScript

const ptr = require("json-pointer");
module.exports = function resolvePointer(data, rootPath, relativePath) {
if (relativePath[0] === "/") return ptr.get(data, relativePath);
const m = relativePath.match(/^(\d+)(.*)/);
relativePath = m[2];
for (let i = 0; i < parseInt(m[1]); i++) {
rootPath = rootPath.replace(/\/[^\/]+$/, "");
}
return ptr.get(data, rootPath + relativePath);
}