UNPKG

flowjv

Version:

Flow based approach to JSON validation!

21 lines (20 loc) 777 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDataFromRefPath = void 0; var parsePath = function (path) { return path .split(".") .map(function (key) { // Normalize return Number.isNaN(parseInt(key)) ? key : parseInt(key); }) .filter(function (v) { return (typeof v === "string" ? v.trim() !== "" : true); }); }; var getPathArr = function (path) { return typeof path === "string" ? parsePath(path) : path; }; var getDataFromKey = function (data, key) { return data === null || data === void 0 ? void 0 : data[key]; }; var getDataFromRefPath = function (data, refPath) { return getPathArr(refPath).reduce(getDataFromKey, data); }; exports.getDataFromRefPath = getDataFromRefPath;