map-anything 2.0.2 → 2.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/README.md CHANGED
@@ -30,15 +30,20 @@ So I made a wrapper function for that. 😃
30
30
 
31
31
  `map-anything` has very good [#TypeScript](#typescript) support as well.
32
32
 
33
- ## Meet the family
33
+ ## Meet the family (more tiny utils with TS support)
34
34
 
35
- - [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)
35
+ - [is-what 🙉](https://github.com/mesqueeb/is-what)
36
+ - [is-where 🙈](https://github.com/mesqueeb/is-where)
36
37
  - [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)
38
+ - [check-anything 👁](https://github.com/mesqueeb/check-anything)
39
+ - [remove-anything ✂️](https://github.com/mesqueeb/remove-anything)
40
+ - [getorset-anything 🐊](https://github.com/mesqueeb/getorset-anything)
41
+ - [map-anything 🗺](https://github.com/mesqueeb/map-anything)
37
42
  - [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)
38
- - [find-and-replace-anything 🎣](https://github.com/mesqueeb/find-and-replace-anything)
39
- - [compare-anything 🛰](https://github.com/mesqueeb/compare-anything)
43
+ - [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)
44
+ - [case-anything 🐫](https://github.com/mesqueeb/case-anything)
40
45
  - [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)
41
- - [is-what 🙉](https://github.com/mesqueeb/is-what)
46
+ - [nestify-anything 🧅](https://github.com/mesqueeb/nestify-anything)
42
47
 
43
48
  ## Usage
44
49
 
package/dist/index.cjs CHANGED
@@ -1,20 +1,23 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  /**
6
4
  * Map each value of an object with provided function, just like `Array.map`
7
- *
8
- * @template T
9
- * @param {T} target
10
- * @param {(value: T, propName: keyof T, array: T[keyof T][]) => any} mapFunction
11
- * @returns {Record<string, any>}
12
5
  */
13
6
  function mapObject(target, mapFunction) {
14
7
  return Object.entries(target).reduce((carry, [key, value], index, array) => {
15
8
  carry[key] = mapFunction(value, key, array);
16
9
  return carry;
17
10
  }, {});
11
+ }
12
+ /**
13
+ * Map each value of a map with provided function, just like `Array.map`
14
+ */
15
+ function mapMap(target, mapFunction) {
16
+ return [...target.entries()].reduce((carry, [key, value], index, array) => {
17
+ carry.set(key, mapFunction(value, key, array));
18
+ return carry;
19
+ }, new Map());
18
20
  }
19
21
 
22
+ exports.mapMap = mapMap;
20
23
  exports.mapObject = mapObject;
package/dist/index.es.js CHANGED
@@ -1,16 +1,20 @@
1
1
  /**
2
2
  * Map each value of an object with provided function, just like `Array.map`
3
- *
4
- * @template T
5
- * @param {T} target
6
- * @param {(value: T, propName: keyof T, array: T[keyof T][]) => any} mapFunction
7
- * @returns {Record<string, any>}
8
3
  */
9
4
  function mapObject(target, mapFunction) {
10
5
  return Object.entries(target).reduce((carry, [key, value], index, array) => {
11
6
  carry[key] = mapFunction(value, key, array);
12
7
  return carry;
13
8
  }, {});
9
+ }
10
+ /**
11
+ * Map each value of a map with provided function, just like `Array.map`
12
+ */
13
+ function mapMap(target, mapFunction) {
14
+ return [...target.entries()].reduce((carry, [key, value], index, array) => {
15
+ carry.set(key, mapFunction(value, key, array));
16
+ return carry;
17
+ }, new Map());
14
18
  }
15
19
 
16
- export { mapObject };
20
+ export { mapMap, mapObject };
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Map each value of an object with provided function, just like `Array.map`
3
- *
4
- * @template T
5
- * @param {T} target
6
- * @param {(value: T, propName: keyof T, array: T[keyof T][]) => any} mapFunction
7
- * @returns {Record<string, any>}
8
3
  */
9
- export declare function mapObject<T extends Record<string, any>, MapFunction extends (value: T[keyof T], propName: keyof T, array: T[keyof T][]) => any>(target: T, mapFunction: MapFunction): {
4
+ export declare function mapObject<T extends Record<string | number | symbol, unknown>, MapFunction extends (value: T[keyof T], propName: keyof T, array: T[keyof T][]) => any>(target: T, mapFunction: MapFunction): {
10
5
  [key in keyof T]: ReturnType<typeof mapFunction>;
11
6
  };
7
+ export type KeyOfMap<M extends Map<unknown, unknown>> = M extends Map<infer K, unknown> ? K : never;
8
+ export type ValueOfMap<M extends Map<unknown, unknown>> = M extends Map<unknown, infer V> ? V : never;
9
+ /**
10
+ * Map each value of a map with provided function, just like `Array.map`
11
+ */
12
+ 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/package.json CHANGED
@@ -2,16 +2,16 @@
2
2
  "name": "map-anything",
3
3
  "sideEffects": false,
4
4
  "type": "module",
5
- "version": "2.0.2",
5
+ "version": "2.1.1",
6
6
  "description": "Array.map but for objects with good TypeScript support. A small and simple integration.",
7
7
  "module": "./dist/index.es.js",
8
8
  "main": "./dist/index.cjs",
9
9
  "types": "./dist/types/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
+ "types": "./dist/types/index.d.ts",
12
13
  "import": "./dist/index.es.js",
13
- "require": "./dist/index.cjs",
14
- "types": "./dist/types/index.d.ts"
14
+ "require": "./dist/index.cjs"
15
15
  }
16
16
  },
17
17
  "files": [
@@ -23,22 +23,22 @@
23
23
  "scripts": {
24
24
  "test": "vitest run",
25
25
  "lint": "tsc --noEmit && eslint ./src --ext .ts",
26
- "build": "rollup -c ./scripts/build.js",
26
+ "build": "rollup --bundleConfigAsCjs -c ./scripts/build.js",
27
27
  "release": "npm run lint && del dist && npm run build && np"
28
28
  },
29
29
  "devDependencies": {
30
- "@typescript-eslint/eslint-plugin": "^5.10.1",
31
- "@typescript-eslint/parser": "^5.10.1",
30
+ "@typescript-eslint/eslint-plugin": "^5.59.2",
31
+ "@typescript-eslint/parser": "^5.59.2",
32
32
  "del-cli": "^4.0.1",
33
- "eslint": "^8.7.0",
34
- "eslint-config-prettier": "^8.3.0",
33
+ "eslint": "^8.40.0",
34
+ "eslint-config-prettier": "^8.8.0",
35
35
  "eslint-plugin-tree-shaking": "^1.10.0",
36
- "np": "^7.6.0",
37
- "prettier": "^2.5.1",
38
- "rollup": "^2.66.1",
39
- "rollup-plugin-typescript2": "^0.31.1",
40
- "typescript": "^4.5.5",
41
- "vitest": "^0.2.3"
36
+ "np": "^7.7.0",
37
+ "prettier": "^2.8.8",
38
+ "rollup": "^3.21.5",
39
+ "rollup-plugin-typescript2": "^0.34.1",
40
+ "typescript": "^4.9.5",
41
+ "vitest": "^0.31.0"
42
42
  },
43
43
  "keywords": [
44
44
  "map-object",