json-joy
Version:
Collection of libraries for building collaborative editing apps.
34 lines (33 loc) • 1.05 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.walk = void 0;
const walk = (value, callback) => {
callback(value);
if (typeof value === 'object') {
if (!value)
return;
switch (value.constructor) {
case Array: {
const arr = value;
const length = arr.length;
for (let i = 0; i < length; i++)
(0, exports.walk)(arr[i], callback);
break;
}
case Object: {
const obj = value;
for (const key in obj)
(0, exports.walk)(obj[key], callback);
break;
}
case Map:
case Set: {
const mapOrSet = value;
// biome-ignore lint: .forEach() is the fastest way to iterate over a Set or Map
mapOrSet.forEach((val) => (0, exports.walk)(val, callback));
break;
}
}
}
};
exports.walk = walk;
;