diff --git a/index.html b/index.html index 8eb3470..4e35991 100644 --- a/index.html +++ b/index.html @@ -1,11 +1,102 @@ + + + Console Styling Playground + - diff --git a/package.json b/package.json index 8be90a5..cf4c8eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.27.7", + "version": "0.27.8", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/objects.ts b/src/objects.ts index b9c0a26..6d5d772 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -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(obj: any, fn: (key: string, value: any) => any): T { + return 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 *