Socket
Socket
Sign inDemoInstall

map-obj

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-obj - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

25

index.js
'use strict';
const isObject = value => typeof value === 'object' && value !== null;
// Customized for this use-case
const isObject = value =>
typeof value === 'object' &&
value !== null &&
const isObjectCustom = value =>
isObject(value) &&
!(value instanceof RegExp) &&

@@ -11,3 +12,3 @@ !(value instanceof Error) &&

const mapObject = (object, fn, options, isSeen = new WeakMap()) => {
const mapObject = (object, mapper, options, isSeen = new WeakMap()) => {
options = {

@@ -28,3 +29,3 @@ deep: false,

const mapArray = array => array.map(element => isObject(element) ? mapObject(element, fn, options, isSeen) : element);
const mapArray = array => array.map(element => isObjectCustom(element) ? mapObject(element, mapper, options, isSeen) : element);
if (Array.isArray(object)) {

@@ -35,8 +36,8 @@ return mapArray(object);

for (const [key, value] of Object.entries(object)) {
let [newKey, newValue] = fn(key, value, object);
let [newKey, newValue] = mapper(key, value, object);
if (options.deep && isObject(newValue)) {
if (options.deep && isObjectCustom(newValue)) {
newValue = Array.isArray(newValue) ?
mapArray(newValue) :
mapObject(newValue, fn, options, isSeen);
mapObject(newValue, mapper, options, isSeen);
}

@@ -50,2 +51,8 @@

module.exports = mapObject;
module.exports = (object, mapper, options) => {
if (!isObject(object)) {
throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
}
return mapObject(object, mapper, options);
};
{
"name": "map-obj",
"version": "4.0.0",
"version": "4.1.0",
"description": "Map object keys and values into a new object",

@@ -5,0 +5,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc