Repository URL to install this package:
|
Version:
1.2.12 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.toEmptyRecursive = exports.recurser = void 0;
var _set = _interopRequireDefault(require("lodash/set"));
var _exotic = require("exotic");
var _chainAbleBoost = require("chain-able-boost");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @desc wraps recursor to simplify usage
* skips array indexes
* skips root value
* slices/dereferences path
*
* @param {*} x data to recurse
* @return {Function} recursor
*/
const recurser = x => {
const recursion = (0, _chainAbleBoost.recurse)(x);
recursion.forEachImportant = function (fn) {
return recursion.forEach((value, key, traverser) => {
if (!key) return;
if ((0, _exotic.isNumberish)(key)) return;
fn(value, traverser.path.slice(0), traverser);
});
};
return recursion;
};
/**
* @desc takes any data, returns, with all nested data turned to empty types
* @param {*} x any data
* @return {*} ALL empty data
*/
exports.recurser = recurser;
const toEmptyRecursive = x => {
const Empty = (0, _exotic.toEmpty)(x);
recurser(x).forEachImportant((value, path) => {
(0, _set.default)(Empty, path, value);
});
return Empty;
};
exports.toEmptyRecursive = toEmptyRecursive;
var _default = toEmptyRecursive;
exports.default = _default;