UNPKG

ts-prime

Version:

A utility library for JavaScript and Typescript.

24 lines (23 loc) 669 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var purry_1 = require("./purry"); var guards_1 = require("./guards"); function path() { return purry_1.purry(_path, arguments); } exports.path = path; function _path(obj, path) { var recursion = function (path, _ro) { if (path.length === 0) return _ro; if (!guards_1.isObject(_ro) && !guards_1.isArray(_ro)) return; var rest = path.slice(1); var firstSegment = path[0]; if (firstSegment in _ro) { return recursion(rest, _ro[firstSegment]); } return; }; return recursion(path, obj); }