@augment-vir/common
Advanced tools
Comparing version 12.2.1 to 12.3.0
import { UnPromise } from '../type'; | ||
import { PropertyValueType } from './object'; | ||
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = { | ||
@@ -7,2 +8,16 @@ [MappedProp in keyof EntireInputGeneric]: MappedValueGeneric; | ||
/** | ||
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in | ||
* that this will not wrap the return value in a promise if any of the new object values are | ||
* promises. This function also requires currying in order to get the types correct. This allows you | ||
* to explicitly state the return type. | ||
* | ||
* @example | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>( | ||
* (key, value) => ({ | ||
* newValue: value.length, | ||
* }), | ||
* ); | ||
*/ | ||
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; | ||
/** | ||
* Creates a new object with the same properties as the input object, but with values set to the | ||
@@ -9,0 +24,0 @@ * result of mapCallback for each property. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mapObjectValues = void 0; | ||
exports.mapObjectValues = exports.mapObjectValuesSync = void 0; | ||
const object_entries_1 = require("./object-entries"); | ||
/** | ||
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in | ||
* that this will not wrap the return value in a promise if any of the new object values are | ||
* promises. This function also requires currying in order to get the types correct. This allows you | ||
* to explicitly state the return type. | ||
* | ||
* @example | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>( | ||
* (key, value) => ({ | ||
* newValue: value.length, | ||
* }), | ||
* ); | ||
*/ | ||
function mapObjectValuesSync(inputObject) { | ||
function innerMap(mapCallback) { | ||
const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => { | ||
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject); | ||
return { | ||
...accum, | ||
[currentKey]: mappedValue, | ||
}; | ||
}, {}); | ||
return mappedObject; | ||
} | ||
return innerMap; | ||
} | ||
exports.mapObjectValuesSync = mapObjectValuesSync; | ||
/** | ||
* Creates a new object with the same properties as the input object, but with values set to the | ||
@@ -7,0 +34,0 @@ * result of mapCallback for each property. |
import { UnPromise } from '../type'; | ||
import { PropertyValueType } from './object'; | ||
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = { | ||
@@ -7,2 +8,16 @@ [MappedProp in keyof EntireInputGeneric]: MappedValueGeneric; | ||
/** | ||
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in | ||
* that this will not wrap the return value in a promise if any of the new object values are | ||
* promises. This function also requires currying in order to get the types correct. This allows you | ||
* to explicitly state the return type. | ||
* | ||
* @example | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>( | ||
* (key, value) => ({ | ||
* newValue: value.length, | ||
* }), | ||
* ); | ||
*/ | ||
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; | ||
/** | ||
* Creates a new object with the same properties as the input object, but with values set to the | ||
@@ -9,0 +24,0 @@ * result of mapCallback for each property. |
import { getObjectTypedKeys } from './object-entries'; | ||
/** | ||
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in | ||
* that this will not wrap the return value in a promise if any of the new object values are | ||
* promises. This function also requires currying in order to get the types correct. This allows you | ||
* to explicitly state the return type. | ||
* | ||
* @example | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>( | ||
* (key, value) => ({ | ||
* newValue: value.length, | ||
* }), | ||
* ); | ||
*/ | ||
export function mapObjectValuesSync(inputObject) { | ||
function innerMap(mapCallback) { | ||
const mappedObject = getObjectTypedKeys(inputObject).reduce((accum, currentKey) => { | ||
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject); | ||
return { | ||
...accum, | ||
[currentKey]: mappedValue, | ||
}; | ||
}, {}); | ||
return mappedObject; | ||
} | ||
return innerMap; | ||
} | ||
/** | ||
* Creates a new object with the same properties as the input object, but with values set to the | ||
@@ -4,0 +30,0 @@ * result of mapCallback for each property. |
import { UnPromise } from '../type'; | ||
import { PropertyValueType } from './object'; | ||
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = { | ||
@@ -7,2 +8,16 @@ [MappedProp in keyof EntireInputGeneric]: MappedValueGeneric; | ||
/** | ||
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in | ||
* that this will not wrap the return value in a promise if any of the new object values are | ||
* promises. This function also requires currying in order to get the types correct. This allows you | ||
* to explicitly state the return type. | ||
* | ||
* @example | ||
* mapObjectValuesSync({objectToIterateOver: 'initial value'})<{objectToIterateOver: number}>( | ||
* (key, value) => ({ | ||
* newValue: value.length, | ||
* }), | ||
* ); | ||
*/ | ||
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; | ||
/** | ||
* Creates a new object with the same properties as the input object, but with values set to the | ||
@@ -9,0 +24,0 @@ * result of mapCallback for each property. |
{ | ||
"name": "@augment-vir/common", | ||
"version": "12.2.1", | ||
"version": "12.3.0", | ||
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common", | ||
@@ -27,6 +27,6 @@ "bugs": { | ||
"dependencies": { | ||
"type-fest": "^3.5.3" | ||
"type-fest": "^3.5.6" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.9.4" | ||
"typescript": "^4.9.5" | ||
}, | ||
@@ -33,0 +33,0 @@ "publishConfig": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
182113
3640
Updatedtype-fest@^3.5.6