UNPKG

@sakuli/commons

Version:

59 lines 2.01 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); function argvLens(path) { return function (obj) { if (path.length <= 0) { return obj; } else { var _a = __read(path), key = _a[0], restOfPath = _a.slice(1); var nested = obj[key]; var isLeaf = restOfPath.length === 0; if (Array.isArray(nested) && isLeaf) { return nested.find(function (o) { return typeof o != "object"; }); } if (Array.isArray(nested)) { var reducedObject = nested .filter(function (o) { return typeof o === "object"; }) .reduce(function (agg, o) { return (__assign({}, agg, o)); }, {}); return argvLens(restOfPath)(reducedObject); } if (typeof nested === "object") { return argvLens(restOfPath)(nested); } else { return nested; } return null; } }; } exports.argvLens = argvLens; //# sourceMappingURL=argv-lens.function.js.map