map-anything 3.0.2 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,14 +1,16 @@
1
- /**
2
- * Map each value of an object with provided function, just like `Array.map`
3
- */
1
+ /** Map each value of an object with provided function, just like `Array.map` */
4
2
  export declare function mapObject<T extends {
5
3
  [key in string | number | symbol]: unknown;
6
4
  }, MapFunction extends (value: T[keyof T], propName: keyof T, array: T[keyof T][]) => any>(target: T, mapFunction: MapFunction): {
7
5
  [key in keyof T]: ReturnType<typeof mapFunction>;
8
6
  };
9
- /**
10
- * Map each value of an object with provided function, just like `Array.map`
11
- */
7
+ /** Map each value of an object with provided function, just like `Array.map` */
8
+ export declare function mapObjectKeys<T extends {
9
+ [key in string | number | symbol]: unknown;
10
+ }, MapFunction extends (propName: keyof T, value: T[keyof T], array: T[keyof T][]) => any>(target: T, mapFunction: MapFunction): {
11
+ [key in ReturnType<typeof mapFunction>]: T[keyof T];
12
+ };
13
+ /** Map each value of an object with provided function, just like `Array.map` */
12
14
  export declare function mapObjectAsync<T extends {
13
15
  [key in string | number | symbol]: unknown;
14
16
  }, MapFunction extends (value: T[keyof T], propName: keyof T, array: T[keyof T][]) => Promise<any>>(target: T, mapFunction: MapFunction): Promise<{
@@ -16,7 +18,5 @@ export declare function mapObjectAsync<T extends {
16
18
  }>;
17
19
  export type KeyOfMap<M extends Map<unknown, unknown>> = M extends Map<infer K, unknown> ? K : never;
18
20
  export type ValueOfMap<M extends Map<unknown, unknown>> = M extends Map<unknown, infer V> ? V : never;
19
- /**
20
- * Map each value of a map with provided function, just like `Array.map`
21
- */
21
+ /** Map each value of a map with provided function, just like `Array.map` */
22
22
  export declare function mapMap<T extends Map<unknown, unknown>, MapFunction extends (value: ValueOfMap<T>, propName: KeyOfMap<T>, array: ValueOfMap<T>[]) => any>(target: T, mapFunction: MapFunction): Map<KeyOfMap<T>, ReturnType<typeof mapFunction>>;
package/dist/index.js CHANGED
@@ -1,15 +1,19 @@
1
- /**
2
- * Map each value of an object with provided function, just like `Array.map`
3
- */
1
+ /** Map each value of an object with provided function, just like `Array.map` */
4
2
  export function mapObject(target, mapFunction) {
5
3
  return Object.entries(target).reduce((carry, [key, value], index, array) => {
6
4
  carry[key] = mapFunction(value, key, array);
7
5
  return carry;
8
6
  }, {});
9
7
  }
10
- /**
11
- * Map each value of an object with provided function, just like `Array.map`
12
- */
8
+ /** Map each value of an object with provided function, just like `Array.map` */
9
+ export function mapObjectKeys(target, mapFunction) {
10
+ return Object.entries(target).reduce((carry, [key, value], index, array) => {
11
+ const newkey = mapFunction(key, value, array);
12
+ carry[newkey] = value;
13
+ return carry;
14
+ }, {});
15
+ }
16
+ /** Map each value of an object with provided function, just like `Array.map` */
13
17
  export async function mapObjectAsync(target, mapFunction) {
14
18
  const entries = Object.entries(target);
15
19
  const promises = entries.map(async ([key, value]) => {
@@ -22,9 +26,7 @@ export async function mapObjectAsync(target, mapFunction) {
22
26
  return carry;
23
27
  }, {});
24
28
  }
25
- /**
26
- * Map each value of a map with provided function, just like `Array.map`
27
- */
29
+ /** Map each value of a map with provided function, just like `Array.map` */
28
30
  export function mapMap(target, mapFunction) {
29
31
  return [...target.entries()].reduce((carry, [key, value], index, array) => {
30
32
  carry.set(key, mapFunction(value, key, array));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "map-anything",
3
- "version": "3.0.2",
3
+ "version": "3.1.1",
4
4
  "description": "Array.map but for objects with good TypeScript support. A small and simple integration.",
5
5
  "type": "module",
6
6
  "sideEffects": false,