UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

30 lines (29 loc) 899 B
export 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++) walk(arr[i], callback); break; } case Object: { const obj = value; for (const key in obj) 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) => walk(val, callback)); break; } } } };