map-obj
Advanced tools
Comparing version 3.1.0 to 4.0.0
declare namespace mapObject { | ||
type Mapper< | ||
SourceObjectType extends {[key: string]: unknown}, | ||
SourceObjectType extends {[key: string]: any}, | ||
MappedObjectKeyType extends string, | ||
MappedObjectValueType extends unknown | ||
MappedObjectValueType | ||
> = ( | ||
@@ -25,3 +25,3 @@ sourceKey: keyof SourceObjectType, | ||
*/ | ||
target?: {[key: string]: unknown}; | ||
target?: {[key: string]: any}; | ||
} | ||
@@ -33,3 +33,3 @@ | ||
interface TargetOptions<TargetObjectType extends {[key: string]: unknown}> extends Options { | ||
interface TargetOptions<TargetObjectType extends {[key: string]: any}> extends Options { | ||
target: TargetObjectType; | ||
@@ -55,5 +55,5 @@ } | ||
SourceObjectType extends object, | ||
TargetObjectType extends {[key: string]: unknown}, | ||
TargetObjectType extends {[key: string]: any}, | ||
MappedObjectKeyType extends string, | ||
MappedObjectValueType extends unknown = unknown | ||
MappedObjectValueType | ||
>( | ||
@@ -71,3 +71,3 @@ source: SourceObjectType, | ||
MappedObjectKeyType extends string, | ||
MappedObjectValueType extends unknown = unknown | ||
MappedObjectValueType | ||
>( | ||
@@ -83,6 +83,6 @@ source: SourceObjectType, | ||
declare function mapObject< | ||
SourceObjectType extends {[key: string]: unknown}, | ||
TargetObjectType extends {[key: string]: unknown}, | ||
SourceObjectType extends {[key: string]: any}, | ||
TargetObjectType extends {[key: string]: any}, | ||
MappedObjectKeyType extends string, | ||
MappedObjectValueType extends unknown | ||
MappedObjectValueType | ||
>( | ||
@@ -98,5 +98,5 @@ source: SourceObjectType, | ||
declare function mapObject< | ||
SourceObjectType extends {[key: string]: unknown}, | ||
SourceObjectType extends {[key: string]: any}, | ||
MappedObjectKeyType extends string, | ||
MappedObjectValueType extends unknown = unknown | ||
MappedObjectValueType | ||
>( | ||
@@ -103,0 +103,0 @@ source: SourceObjectType, |
13
index.js
@@ -12,6 +12,7 @@ 'use strict'; | ||
const mapObject = (object, fn, options, isSeen = new WeakMap()) => { | ||
options = Object.assign({ | ||
options = { | ||
deep: false, | ||
target: {} | ||
}, options); | ||
target: {}, | ||
...options | ||
}; | ||
@@ -27,3 +28,3 @@ if (isSeen.has(object)) { | ||
const mapArray = array => array.map(x => isObject(x) ? mapObject(x, fn, options, isSeen) : x); | ||
const mapArray = array => array.map(element => isObject(element) ? mapObject(element, fn, options, isSeen) : element); | ||
if (Array.isArray(object)) { | ||
@@ -33,5 +34,3 @@ return mapArray(object); | ||
/// TODO: Use `Object.entries()` when targeting Node.js 8 | ||
for (const key of Object.keys(object)) { | ||
const value = object[key]; | ||
for (const [key, value] of Object.entries(object)) { | ||
let [newKey, newValue] = fn(key, value, object); | ||
@@ -38,0 +37,0 @@ |
{ | ||
"name": "map-obj", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Map object keys and values into a new object", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8" | ||
}, | ||
@@ -39,6 +39,6 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"ava": "^2.0.0", | ||
"tsd": "^0.7.3", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -25,3 +25,3 @@ # map-obj [![Build Status](https://travis-ci.org/sindresorhus/map-obj.svg?branch=master)](https://travis-ci.org/sindresorhus/map-obj) | ||
### mapObject(source, mapper, [options]) | ||
### mapObject(source, mapper, options?) | ||
@@ -67,4 +67,12 @@ #### source | ||
## License | ||
--- | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-map-obj?utm_source=npm-map-obj&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
6797
77
131