'use strict';


function deepMap(object, fn, opts) {
  opts = opts || {};

  if (!fn) {
    throwError(Error, 'transformFn must be defined');
  }

  if (!isFunction(fn)) {
    throwError(TypeError, 'transformFn must be a function');
  }

  if (!isObject(opts)) {
    throwError(TypeError, 'options must be an object or undefined');
  }

  return transform(object, fn, opts);
}


function transform(value, fn, opts, key) {
  return Array.isArray(value) ? mapArray(value, fn, opts) :
    isObject(value) ? mapObject(value, fn, opts) :
    fn.call(opts.thisArg, value, key);
}


function mapArray(array, fn, opts) {
  var result = opts.inPlace ? array : [];

  var length = array.length;
  for (var i = 0; i < length; i++) {
    result[i] = transform(array[i], fn, opts, i);
  }

  return result;
}


function mapObject(object, fn, opts) {
  var result = opts.inPlace ? object : {};

  for (var key in object) {
    result[key] = transform(object[key], fn, opts, key);
  }

  return result;
}


function isFunction(value) {
  return typeof value === 'function';
}


function isObject(value) {
  return typeof value === 'object' || isFunction(value);
}


function throwError(ErrorContructor, message) {
  var err = new ErrorContructor(message);
  Error.captureStackTrace(err, deepMap);
  throw err;
}


module.exports = deepMap;

@@ -8,17 +8,16 @@
 rict';%0A%0A
-%0A
 function
@@ -130,33 +130,32 @@
  defined');%0A  %7D%0A
-%0A
   if (!isFunctio
@@ -228,17 +228,16 @@
 ');%0A  %7D%0A
-%0A
   if (!i
@@ -364,25 +364,24 @@
 , opts);%0A%7D%0A%0A
-%0A
 function tra
@@ -560,25 +560,24 @@
 e, key);%0A%7D%0A%0A
-%0A
 function map
@@ -777,33 +777,32 @@
 turn result;%0A%7D%0A%0A
-%0A
 function mapObje
@@ -974,25 +974,24 @@
  result;%0A%7D%0A%0A
-%0A
 function isF
@@ -1044,25 +1044,24 @@
 nction';%0A%7D%0A%0A
-%0A
 function isO
@@ -1135,17 +1135,16 @@
 ue);%0A%7D%0A%0A
-%0A
 function
@@ -1283,12 +1283,11 @@
 rr;%0A
+
 %7D%0A%0A
-%0A
 modu

Remove multiple line breaks