Added object map
Some checks failed
Build / Build NPM Project (push) Successful in 1m59s
Build / Publish Documentation (push) Failing after 32s
Build / Tag Version (push) Successful in 43s

This commit is contained in:
2025-10-20 15:17:51 -04:00
parent 34227e5c4b
commit a7b19900da
3 changed files with 108 additions and 6 deletions

View File

@@ -293,6 +293,17 @@ export function mixin(target: any, constructors: any[]) {
});
}
/**
* Run a map function on each property
* @param obj Object that will be iterated
* @param {(key: string, value: any) => any} fn Transformer function - receives key & value
* @returns {{}}
*/
export function objectMap<T>(obj: any, fn: (key: string, value: any) => any): T {
return <any>Object.entries(obj).map(([key, value]: [string, any]) => [key, fn(key, value)])
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
}
/**
* Parse JSON but return the original string if it fails
*