map-anything 2.1.1 → 2.2.0
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/cjs/index.cjs +30 -0
- package/dist/cjs/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +26 -0
- package/package.json +28 -22
- package/dist/index.cjs +0 -23
- package/dist/index.es.js +0 -20
- package/dist/types/index.d.ts +0 -12
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function mapObject(target, mapFunction) {
|
|
4
|
+
return Object.entries(target).reduce((carry, [key, value], index, array) => {
|
|
5
|
+
carry[key] = mapFunction(value, key, array);
|
|
6
|
+
return carry;
|
|
7
|
+
}, {});
|
|
8
|
+
}
|
|
9
|
+
async function mapObjectAsync(target, mapFunction) {
|
|
10
|
+
const entries = Object.entries(target);
|
|
11
|
+
const promises = entries.map(async ([key, value]) => {
|
|
12
|
+
const newValue = await mapFunction(value, key, target);
|
|
13
|
+
return [key, newValue];
|
|
14
|
+
});
|
|
15
|
+
const results = await Promise.all(promises);
|
|
16
|
+
return results.reduce((carry, [key, value]) => {
|
|
17
|
+
carry[key] = value;
|
|
18
|
+
return carry;
|
|
19
|
+
}, {});
|
|
20
|
+
}
|
|
21
|
+
function mapMap(target, mapFunction) {
|
|
22
|
+
return [...target.entries()].reduce((carry, [key, value], index, array) => {
|
|
23
|
+
carry.set(key, mapFunction(value, key, array));
|
|
24
|
+
return carry;
|
|
25
|
+
}, /* @__PURE__ */ new Map());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.mapMap = mapMap;
|
|
29
|
+
exports.mapObject = mapObject;
|
|
30
|
+
exports.mapObjectAsync = mapObjectAsync;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map each value of an object with provided function, just like `Array.map`
|
|
3
|
+
*/
|
|
4
|
+
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): {
|
|
5
|
+
[key in keyof T]: ReturnType<typeof mapFunction>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Map each value of an object with provided function, just like `Array.map`
|
|
9
|
+
*/
|
|
10
|
+
declare function mapObjectAsync<T extends Record<string | number | symbol, unknown>, MapFunction extends (value: T[keyof T], propName: keyof T, array: T[keyof T][]) => Promise<any>>(target: T, mapFunction: MapFunction): Promise<{
|
|
11
|
+
[key in keyof T]: Awaited<ReturnType<typeof mapFunction>>;
|
|
12
|
+
}>;
|
|
13
|
+
type KeyOfMap<M extends Map<unknown, unknown>> = M extends Map<infer K, unknown> ? K : never;
|
|
14
|
+
type ValueOfMap<M extends Map<unknown, unknown>> = M extends Map<unknown, infer V> ? V : never;
|
|
15
|
+
/**
|
|
16
|
+
* Map each value of a map with provided function, just like `Array.map`
|
|
17
|
+
*/
|
|
18
|
+
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>>;
|
|
19
|
+
|
|
20
|
+
export { type KeyOfMap, type ValueOfMap, mapMap, mapObject, mapObjectAsync };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map each value of an object with provided function, just like `Array.map`
|
|
3
|
+
*/
|
|
4
|
+
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): {
|
|
5
|
+
[key in keyof T]: ReturnType<typeof mapFunction>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Map each value of an object with provided function, just like `Array.map`
|
|
9
|
+
*/
|
|
10
|
+
declare function mapObjectAsync<T extends Record<string | number | symbol, unknown>, MapFunction extends (value: T[keyof T], propName: keyof T, array: T[keyof T][]) => Promise<any>>(target: T, mapFunction: MapFunction): Promise<{
|
|
11
|
+
[key in keyof T]: Awaited<ReturnType<typeof mapFunction>>;
|
|
12
|
+
}>;
|
|
13
|
+
type KeyOfMap<M extends Map<unknown, unknown>> = M extends Map<infer K, unknown> ? K : never;
|
|
14
|
+
type ValueOfMap<M extends Map<unknown, unknown>> = M extends Map<unknown, infer V> ? V : never;
|
|
15
|
+
/**
|
|
16
|
+
* Map each value of a map with provided function, just like `Array.map`
|
|
17
|
+
*/
|
|
18
|
+
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>>;
|
|
19
|
+
|
|
20
|
+
export { type KeyOfMap, type ValueOfMap, mapMap, mapObject, mapObjectAsync };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function mapObject(target, mapFunction) {
|
|
2
|
+
return Object.entries(target).reduce((carry, [key, value], index, array) => {
|
|
3
|
+
carry[key] = mapFunction(value, key, array);
|
|
4
|
+
return carry;
|
|
5
|
+
}, {});
|
|
6
|
+
}
|
|
7
|
+
async function mapObjectAsync(target, mapFunction) {
|
|
8
|
+
const entries = Object.entries(target);
|
|
9
|
+
const promises = entries.map(async ([key, value]) => {
|
|
10
|
+
const newValue = await mapFunction(value, key, target);
|
|
11
|
+
return [key, newValue];
|
|
12
|
+
});
|
|
13
|
+
const results = await Promise.all(promises);
|
|
14
|
+
return results.reduce((carry, [key, value]) => {
|
|
15
|
+
carry[key] = value;
|
|
16
|
+
return carry;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
function mapMap(target, mapFunction) {
|
|
20
|
+
return [...target.entries()].reduce((carry, [key, value], index, array) => {
|
|
21
|
+
carry.set(key, mapFunction(value, key, array));
|
|
22
|
+
return carry;
|
|
23
|
+
}, /* @__PURE__ */ new Map());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { mapMap, mapObject, mapObjectAsync };
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "map-anything",
|
|
3
|
-
"
|
|
4
|
-
"type": "module",
|
|
5
|
-
"version": "2.1.1",
|
|
3
|
+
"version": "2.2.0",
|
|
6
4
|
"description": "Array.map but for objects with good TypeScript support. A small and simple integration.",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"types": "./dist/
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
"require": {
|
|
13
|
+
"types": "./dist/cjs/index.d.cts",
|
|
14
|
+
"default": "./dist/cjs/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
"files": [
|
|
@@ -23,22 +28,23 @@
|
|
|
23
28
|
"scripts": {
|
|
24
29
|
"test": "vitest run",
|
|
25
30
|
"lint": "tsc --noEmit && eslint ./src --ext .ts",
|
|
26
|
-
"build": "rollup
|
|
31
|
+
"build": "rollup -c ./rollup.config.js",
|
|
27
32
|
"release": "npm run lint && del dist && npm run build && np"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
31
|
-
"@typescript-eslint/parser": "^
|
|
32
|
-
"del-cli": "^
|
|
33
|
-
"eslint": "^8.
|
|
34
|
-
"eslint-config-prettier": "^
|
|
35
|
-
"eslint-plugin-tree-shaking": "^1.
|
|
36
|
-
"np": "^
|
|
37
|
-
"prettier": "^
|
|
38
|
-
"rollup": "^
|
|
39
|
-
"rollup-plugin-
|
|
40
|
-
"
|
|
41
|
-
"
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
36
|
+
"@typescript-eslint/parser": "^6.12.0",
|
|
37
|
+
"del-cli": "^5.1.0",
|
|
38
|
+
"eslint": "^8.54.0",
|
|
39
|
+
"eslint-config-prettier": "^9.0.0",
|
|
40
|
+
"eslint-plugin-tree-shaking": "^1.12.0",
|
|
41
|
+
"np": "^8.0.4",
|
|
42
|
+
"prettier": "^3.1.0",
|
|
43
|
+
"rollup": "^4.5.2",
|
|
44
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
45
|
+
"rollup-plugin-esbuild": "^6.1.0",
|
|
46
|
+
"typescript": "^5.3.2",
|
|
47
|
+
"vitest": "^0.34.6"
|
|
42
48
|
},
|
|
43
49
|
"keywords": [
|
|
44
50
|
"map-object",
|
package/dist/index.cjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Map each value of an object with provided function, just like `Array.map`
|
|
5
|
-
*/
|
|
6
|
-
function mapObject(target, mapFunction) {
|
|
7
|
-
return Object.entries(target).reduce((carry, [key, value], index, array) => {
|
|
8
|
-
carry[key] = mapFunction(value, key, array);
|
|
9
|
-
return carry;
|
|
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());
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
exports.mapMap = mapMap;
|
|
23
|
-
exports.mapObject = mapObject;
|
package/dist/index.es.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Map each value of an object with provided function, just like `Array.map`
|
|
3
|
-
*/
|
|
4
|
-
function mapObject(target, mapFunction) {
|
|
5
|
-
return Object.entries(target).reduce((carry, [key, value], index, array) => {
|
|
6
|
-
carry[key] = mapFunction(value, key, array);
|
|
7
|
-
return carry;
|
|
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());
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { mapMap, mapObject };
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Map each value of an object with provided function, just like `Array.map`
|
|
3
|
-
*/
|
|
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): {
|
|
5
|
-
[key in keyof T]: ReturnType<typeof mapFunction>;
|
|
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>>;
|