UNPKG

pragmatic-fp-ts

Version:

Opinionated functional programming library with easy use in mind

22 lines (21 loc) 733 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasIn = void 0; const main_1 = require("./main"); const checkIfPathExists = (path, obj) => (0, main_1.isEmpty)(path) ? !(0, main_1.isNil)(obj) : (0, main_1.isEmpty)(obj) ? false : checkIfPathExists(path.slice(1), obj[path[0]]); function hasIn(path, dict) { if (arguments.length === 1) { return (_dict) => hasIn(path, _dict); } const thePath = (0, main_1.getValueOr)([], path); const theDict = (0, main_1.getValueOr)({}, dict); if ((0, main_1.isEmpty)(thePath) || (0, main_1.isEmpty)(theDict)) { return false; } return checkIfPathExists(thePath, theDict); } exports.hasIn = hasIn;