@sparted/shared-library 1.0.5 → 1.0.6
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/array/array-to-map.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare type ArrayToMapOptions<InitialValue, ModifiedValue = InitialValue
|
|
|
6
6
|
/**
|
|
7
7
|
* Transform the initial data into another value
|
|
8
8
|
*/
|
|
9
|
-
dataModifier?: (value: InitialValue) => ModifiedValue;
|
|
9
|
+
dataModifier?: (value: InitialValue, map: Readonly<Record<string, ModifiedValue>>) => ModifiedValue;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Transform an array to a map.
|
package/array/array-to-map.js
CHANGED
|
@@ -10,7 +10,7 @@ const arrayToMap = (array, options) => {
|
|
|
10
10
|
return array.reduce((acc, current) => {
|
|
11
11
|
const key = selectKey(current);
|
|
12
12
|
const value = options.dataModifier
|
|
13
|
-
? options.dataModifier(current)
|
|
13
|
+
? options.dataModifier(current, acc)
|
|
14
14
|
: current;
|
|
15
15
|
return Object.assign(Object.assign({}, acc), { [key]: value });
|
|
16
16
|
}, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-to-map.js","sources":["../../src/array/array-to-map.ts"],"sourcesContent":["export type ArrayToMapOptions<InitialValue, ModifiedValue = InitialValue> = {\n /**\n * Function to return the key used in the map.\n */\n selectKey: (value: InitialValue) => string,\n /**\n * Transform the initial data into another value\n */\n dataModifier?: (value: InitialValue) => ModifiedValue;\n};\n\n/**\n * Transform an array to a map.\n */\nexport const arrayToMap = <InitialValue, ModifiedValue = InitialValue>(\n array: ReadonlyArray<InitialValue>,\n options: ArrayToMapOptions<InitialValue, ModifiedValue>,\n) => {\n const { selectKey } = options;\n\n return array.reduce<Record<string, ModifiedValue>>((acc, current) => {\n const key = selectKey(current);\n const value = options.dataModifier\n ? options.dataModifier(current)\n : current;\n\n return {\n ...acc,\n [key]: value as ModifiedValue,\n };\n }, {});\n};\n"],"names":[],"mappings":";;;;AAWA;;AAEG;MACU,UAAU,GAAG,CACxB,KAAkC,EAClC,OAAuD,KACrD;AACF,IAAA,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,OAAO,KAAK,CAAC,MAAM,CAAgC,CAAC,GAAG,EAAE,OAAO,KAAI;AAClE,QAAA,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAC/B,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"array-to-map.js","sources":["../../src/array/array-to-map.ts"],"sourcesContent":["export type ArrayToMapOptions<InitialValue, ModifiedValue = InitialValue> = {\n /**\n * Function to return the key used in the map.\n */\n selectKey: (value: InitialValue) => string,\n /**\n * Transform the initial data into another value\n */\n dataModifier?: (value: InitialValue, map: Readonly<Record<string, ModifiedValue>>) => ModifiedValue;\n};\n\n/**\n * Transform an array to a map.\n */\nexport const arrayToMap = <InitialValue, ModifiedValue = InitialValue>(\n array: ReadonlyArray<InitialValue>,\n options: ArrayToMapOptions<InitialValue, ModifiedValue>,\n) => {\n const { selectKey } = options;\n\n return array.reduce<Record<string, ModifiedValue>>((acc, current) => {\n const key = selectKey(current);\n const value = options.dataModifier\n ? options.dataModifier(current, acc)\n : current;\n\n return {\n ...acc,\n [key]: value as ModifiedValue,\n };\n }, {});\n};\n"],"names":[],"mappings":";;;;AAWA;;AAEG;MACU,UAAU,GAAG,CACxB,KAAkC,EAClC,OAAuD,KACrD;AACF,IAAA,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,OAAO,KAAK,CAAC,MAAM,CAAgC,CAAC,GAAG,EAAE,OAAO,KAAI;AAClE,QAAA,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAC/B,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY;cAC9B,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC;cAClC,OAAO,CAAC;AAEZ,QAAA,OAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACK,GAAG,CACN,EAAA,EAAA,CAAC,GAAG,GAAG,KAAsB,EAC7B,CAAA,CAAA;KACH,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
|