Added everyNested to walk nested objects/arrays
Build / Publish Docs (push) Successful in 31s
Build / Build NPM Project (push) Successful in 36s
Build / Tag Version (push) Successful in 7s

This commit is contained in:
2026-10-08 11:28:05 -04:00
parent 59b03d5b51
commit 54aaa58990
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.30.10", "version": "0.30.11",
"description": "Utility library", "description": "Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",
+9
View File
@@ -165,6 +165,15 @@ export function encodeQuery(data: any): string {
).join('&'); ).join('&');
} }
/** Recursively walks obj/arrays, calling cb(dotPath, value) for every leaf+branch prop */
export function everyNested(obj: any, cb: (key: string, value: any) => void, prefix = ''){
Object.entries(obj).forEach(([k, v]) => {
const key = prefix ? `${prefix}.${k}` : k;
cb(key, v);
if (v && typeof v === 'object') everyNested(v, cb, key);
});
}
/** /**
* Recursively flatten a nested object, while maintaining key structure * Recursively flatten a nested object, while maintaining key structure
* *