Socket
Socket
Sign inDemoInstall

map-obj

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.0 to 4.2.0

21

index.d.ts

@@ -10,3 +10,7 @@ declare namespace mapObject {

source: SourceObjectType
) => [MappedObjectKeyType, MappedObjectValueType];
) => [
targetKey: MappedObjectKeyType,
targetValue: MappedObjectValueType,
mapperOptions?: mapObject.MapperOptions
];

@@ -36,2 +40,11 @@ interface Options {

}
interface MapperOptions {
/**
Whether `targetValue` should be recursed. Requires `deep: true`.
@default true
*/
shouldRecurse?: boolean;
}
}

@@ -51,2 +64,8 @@

//=> {bar: 'foo'}
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value]);
//=> {foo: true, bar: {bAz: true}}
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value], {deep: true});
//=> {foo: true, bar: {baz: true}}
```

@@ -53,0 +72,0 @@ */

4

index.js

@@ -34,5 +34,5 @@ 'use strict';

for (const [key, value] of Object.entries(object)) {
let [newKey, newValue] = mapper(key, value, object);
let [newKey, newValue, {shouldRecurse = true} = {}] = mapper(key, value, object);
if (options.deep && isObjectCustom(newValue)) {
if (options.deep && shouldRecurse && isObjectCustom(newValue)) {
newValue = Array.isArray(newValue) ?

@@ -39,0 +39,0 @@ mapArray(newValue) :

{
"name": "map-obj",
"version": "4.1.0",
"version": "4.2.0",
"description": "Map object keys and values into a new object",
"license": "MIT",
"repository": "sindresorhus/map-obj",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},

@@ -39,5 +40,5 @@ "engines": {

"ava": "^2.0.0",
"tsd": "^0.7.3",
"tsd": "^0.14.0",
"xo": "^0.24.0"
}
}

@@ -1,6 +0,5 @@

# map-obj [![Build Status](https://travis-ci.org/sindresorhus/map-obj.svg?branch=master)](https://travis-ci.org/sindresorhus/map-obj)
# map-obj
> Map object keys and values into a new object
## Install

@@ -12,3 +11,2 @@

## Usage

@@ -21,5 +19,10 @@

//=> {bar: 'foo'}
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value]);
//=> {foo: true, bar: {bAz: true}}
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value], {deep: true});
//=> {foo: true, bar: {baz: true}}
```
## API

@@ -37,9 +40,15 @@

Type: `Function`
Type: `(sourceKey, sourceValue, source) => [targetKey, targetValue, mapperOptions?]`
Mapping function.
- It has signature `mapper(sourceKey, sourceValue, source)`.
- It must return a two item array: `[targetKey, targetValue]`.
##### mapperOptions
###### shouldRecurse
Type: `boolean`\
Default: `true`
Whether `targetValue` should be recursed. Requires `deep: true`.
#### options

@@ -51,3 +60,3 @@

Type: `boolean`<br>
Type: `boolean`\
Default: `false`

@@ -59,3 +68,3 @@

Type: `object`<br>
Type: `object`\
Default: `{}`

@@ -65,3 +74,2 @@

## Related

@@ -71,3 +79,2 @@

---

@@ -74,0 +81,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc