@augment-vir/common 12.2.1 → 12.3.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/augments/object/map-object.d.ts +15 -0
- package/dist/cjs/augments/object/map-object.js +28 -1
- package/dist/esm/augments/object/map-object.d.ts +15 -0
- package/dist/esm/augments/object/map-object.js +26 -0
- package/dist/types/augments/object/map-object.d.ts +15 -0
- package/package.json +3 -3
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { UnPromise } from '../type';
|
|
2
|
+
import { PropertyValueType } from './object';
|
|
2
3
|
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
|
|
3
4
|
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
|
|
4
5
|
};
|
|
5
6
|
export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>;
|
|
7
|
+
/**
|
|
8
|
+
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
9
|
+
* that this will not wrap the return value in a promise if any of the new object values are
|
|
10
|
+
* promises. This function also requires currying in order to get the types correct. This allows you
|
|
11
|
+
* to explicitly state the return type.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>(
|
|
15
|
+
* (key, value) => ({
|
|
16
|
+
* newValue: value.length,
|
|
17
|
+
* }),
|
|
18
|
+
* );
|
|
19
|
+
*/
|
|
20
|
+
export declare function mapObjectValuesSync<EntireInputGeneric extends object>(inputObject: EntireInputGeneric): <OutputObjectGeneric extends object>(mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[keyof EntireInputGeneric], fullObject: EntireInputGeneric) => never extends PropertyValueType<OutputObjectGeneric> ? any : PropertyValueType<OutputObjectGeneric>) => OutputObjectGeneric;
|
|
6
21
|
/**
|
|
7
22
|
* Creates a new object with the same properties as the input object, but with values set to the
|
|
8
23
|
* result of mapCallback for each property.
|
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapObjectValues = void 0;
|
|
3
|
+
exports.mapObjectValues = exports.mapObjectValuesSync = void 0;
|
|
4
4
|
const object_entries_1 = require("./object-entries");
|
|
5
|
+
/**
|
|
6
|
+
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
7
|
+
* that this will not wrap the return value in a promise if any of the new object values are
|
|
8
|
+
* promises. This function also requires currying in order to get the types correct. This allows you
|
|
9
|
+
* to explicitly state the return type.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>(
|
|
13
|
+
* (key, value) => ({
|
|
14
|
+
* newValue: value.length,
|
|
15
|
+
* }),
|
|
16
|
+
* );
|
|
17
|
+
*/
|
|
18
|
+
function mapObjectValuesSync(inputObject) {
|
|
19
|
+
function innerMap(mapCallback) {
|
|
20
|
+
const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
|
|
21
|
+
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
22
|
+
return {
|
|
23
|
+
...accum,
|
|
24
|
+
[currentKey]: mappedValue,
|
|
25
|
+
};
|
|
26
|
+
}, {});
|
|
27
|
+
return mappedObject;
|
|
28
|
+
}
|
|
29
|
+
return innerMap;
|
|
30
|
+
}
|
|
31
|
+
exports.mapObjectValuesSync = mapObjectValuesSync;
|
|
5
32
|
/**
|
|
6
33
|
* Creates a new object with the same properties as the input object, but with values set to the
|
|
7
34
|
* result of mapCallback for each property.
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { UnPromise } from '../type';
|
|
2
|
+
import { PropertyValueType } from './object';
|
|
2
3
|
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
|
|
3
4
|
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
|
|
4
5
|
};
|
|
5
6
|
export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>;
|
|
7
|
+
/**
|
|
8
|
+
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
9
|
+
* that this will not wrap the return value in a promise if any of the new object values are
|
|
10
|
+
* promises. This function also requires currying in order to get the types correct. This allows you
|
|
11
|
+
* to explicitly state the return type.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>(
|
|
15
|
+
* (key, value) => ({
|
|
16
|
+
* newValue: value.length,
|
|
17
|
+
* }),
|
|
18
|
+
* );
|
|
19
|
+
*/
|
|
20
|
+
export declare function mapObjectValuesSync<EntireInputGeneric extends object>(inputObject: EntireInputGeneric): <OutputObjectGeneric extends object>(mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[keyof EntireInputGeneric], fullObject: EntireInputGeneric) => never extends PropertyValueType<OutputObjectGeneric> ? any : PropertyValueType<OutputObjectGeneric>) => OutputObjectGeneric;
|
|
6
21
|
/**
|
|
7
22
|
* Creates a new object with the same properties as the input object, but with values set to the
|
|
8
23
|
* result of mapCallback for each property.
|
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { getObjectTypedKeys } from './object-entries';
|
|
2
|
+
/**
|
|
3
|
+
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
4
|
+
* that this will not wrap the return value in a promise if any of the new object values are
|
|
5
|
+
* promises. This function also requires currying in order to get the types correct. This allows you
|
|
6
|
+
* to explicitly state the return type.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>(
|
|
10
|
+
* (key, value) => ({
|
|
11
|
+
* newValue: value.length,
|
|
12
|
+
* }),
|
|
13
|
+
* );
|
|
14
|
+
*/
|
|
15
|
+
export function mapObjectValuesSync(inputObject) {
|
|
16
|
+
function innerMap(mapCallback) {
|
|
17
|
+
const mappedObject = getObjectTypedKeys(inputObject).reduce((accum, currentKey) => {
|
|
18
|
+
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
19
|
+
return {
|
|
20
|
+
...accum,
|
|
21
|
+
[currentKey]: mappedValue,
|
|
22
|
+
};
|
|
23
|
+
}, {});
|
|
24
|
+
return mappedObject;
|
|
25
|
+
}
|
|
26
|
+
return innerMap;
|
|
27
|
+
}
|
|
2
28
|
/**
|
|
3
29
|
* Creates a new object with the same properties as the input object, but with values set to the
|
|
4
30
|
* result of mapCallback for each property.
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { UnPromise } from '../type';
|
|
2
|
+
import { PropertyValueType } from './object';
|
|
2
3
|
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
|
|
3
4
|
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
|
|
4
5
|
};
|
|
5
6
|
export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>;
|
|
7
|
+
/**
|
|
8
|
+
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
9
|
+
* that this will not wrap the return value in a promise if any of the new object values are
|
|
10
|
+
* promises. This function also requires currying in order to get the types correct. This allows you
|
|
11
|
+
* to explicitly state the return type.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>(
|
|
15
|
+
* (key, value) => ({
|
|
16
|
+
* newValue: value.length,
|
|
17
|
+
* }),
|
|
18
|
+
* );
|
|
19
|
+
*/
|
|
20
|
+
export declare function mapObjectValuesSync<EntireInputGeneric extends object>(inputObject: EntireInputGeneric): <OutputObjectGeneric extends object>(mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[keyof EntireInputGeneric], fullObject: EntireInputGeneric) => never extends PropertyValueType<OutputObjectGeneric> ? any : PropertyValueType<OutputObjectGeneric>) => OutputObjectGeneric;
|
|
6
21
|
/**
|
|
7
22
|
* Creates a new object with the same properties as the input object, but with values set to the
|
|
8
23
|
* result of mapCallback for each property.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/electrovir/augment-vir/issues"
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"test:types": "tsc --noEmit"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"type-fest": "^3.5.
|
|
27
|
+
"type-fest": "^3.5.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"typescript": "^4.9.
|
|
30
|
+
"typescript": "^4.9.5"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|