60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
|
|
"use strict";
|
||
|
|
var __defProp = Object.defineProperty;
|
||
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||
|
|
var __export = (target, all) => {
|
||
|
|
for (var name in all)
|
||
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
||
|
|
};
|
||
|
|
var __copyProps = (to, from, except, desc) => {
|
||
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
||
|
|
for (let key of __getOwnPropNames(from))
|
||
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
||
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||
|
|
}
|
||
|
|
return to;
|
||
|
|
};
|
||
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||
|
|
|
||
|
|
// src/walk-object.ts
|
||
|
|
var walk_object_exports = {};
|
||
|
|
__export(walk_object_exports, {
|
||
|
|
mapObject: () => mapObject,
|
||
|
|
walkObject: () => walkObject
|
||
|
|
});
|
||
|
|
module.exports = __toCommonJS(walk_object_exports);
|
||
|
|
function isObject(value) {
|
||
|
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
||
|
|
}
|
||
|
|
function walkObject(target, predicate, options = {}) {
|
||
|
|
const { stop, getKey } = options;
|
||
|
|
function inner(value, path = []) {
|
||
|
|
var _a;
|
||
|
|
if (isObject(value) || Array.isArray(value)) {
|
||
|
|
const result = {};
|
||
|
|
for (const [prop, child] of Object.entries(value)) {
|
||
|
|
const key = (_a = getKey == null ? void 0 : getKey(prop)) != null ? _a : prop;
|
||
|
|
const childPath = [...path, key];
|
||
|
|
if (stop == null ? void 0 : stop(value, childPath)) {
|
||
|
|
return predicate(value, path);
|
||
|
|
}
|
||
|
|
result[key] = inner(child, childPath);
|
||
|
|
}
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
return predicate(value, path);
|
||
|
|
}
|
||
|
|
return inner(target);
|
||
|
|
}
|
||
|
|
function mapObject(obj, fn) {
|
||
|
|
if (!isObject(obj))
|
||
|
|
return fn(obj);
|
||
|
|
return walkObject(obj, (value) => fn(value));
|
||
|
|
}
|
||
|
|
// Annotate the CommonJS export names for ESM import in node:
|
||
|
|
0 && (module.exports = {
|
||
|
|
mapObject,
|
||
|
|
walkObject
|
||
|
|
});
|