Repository URL to install this package:
|
Version:
1.2.18 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.finderMethod = finderMethod;
exports.findOne = findOne;
exports.findAll = findAll;
exports.find = exports.default = void 0;
var _ramda = require("ramda");
var _forOwn = _interopRequireDefault(require("lodash/forOwn"));
var _chainAbleBoost = require("chain-able-boost");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// @TODO good place to do logging
// @TODO return .find as a chain
const find = (specification, path, data) => {
let found = []; // turn primitive values into eq functions
(0, _forOwn.default)(specification, (value, key) => {
if ((0, _chainAbleBoost.isPrimitive)(value)) {
specification[key] = (0, _ramda.equals)(value);
}
});
(0, _chainAbleBoost.traverse)(data).forEach((key, x, traverser) => {
const isFound = !(0, _chainAbleBoost.isNil)(x) && !found.includes(x) && (0, _chainAbleBoost.isFunction)(specification) ? specification(x) : (0, _chainAbleBoost.where)(specification, x);
if (isFound) {
found.push(x); // do not go any deeper
traverser.skip();
} // console.log({ [key]: x, isFound })
});
return found;
};
exports.find = find;
function finderMethod(specification, path) {
return this.findAll(specification, path);
} // @TODO this would .stop() on first find
function findOne(specification, path) {
return this.find(specification, path)[0];
}
function findAll(specification, path) {
let data;
if ((0, _chainAbleBoost.isNil)(path)) data = this.entries(true);else data = this.get(path);
return find(specification, path, data);
}
var _default = find;
exports.default = _default;