(function webpackUniversalModuleDefinition(root,factory){if(typeof exports==="object"&&typeof module==="object")module.exports=factory();else if(typeof define==="function"&&define.amd)define([],factory);else if(typeof exports==="object")exports["json2csv"]=factory();else root["json2csv"]=factory()})(this,function(){return function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:false};modules[moduleId].call(module.exports,module,module.exports,__webpack_require__);module.loaded=true;return module.exports}__webpack_require__.m=modules;__webpack_require__.c=installedModules;__webpack_require__.p="";return __webpack_require__(0)}([function(module,exports,__webpack_require__){(function(process){var os=__webpack_require__(2);var lodashGet=__webpack_require__(3);var lodashFlatten=__webpack_require__(4);var lodashUniq=__webpack_require__(5);var lodashSet=__webpack_require__(6);var lodashCloneDeep=__webpack_require__(7);var flatten=__webpack_require__(9);module.exports=function(params,callback){var hasCallback=typeof callback==="function";var err;try{checkParams(params)}catch(err){if(hasCallback){return process.nextTick(function(){callback(err)})}else{throw err}}var titles=createColumnTitles(params);var csv=createColumnContent(params,titles);if(hasCallback){return process.nextTick(function(){callback(null,csv)})}else{return csv}};function checkParams(params){params.data=params.data||[];if(!Array.isArray(params.data)){params.data=[params.data]}if(params.flatten){params.data=params.data.map(flatten)}if(!params.fields&&(params.data.length===0||typeof params.data[0]!=="object")){throw new Error('params should include "fields" and/or non-empty "data" array of objects')}if(!params.fields){var dataFields=params.data.map(function(item){return Object.keys(item)});dataFields=lodashFlatten(dataFields);params.fields=lodashUniq(dataFields)}if(params.fieldNames&¶ms.fieldNames.length!==params.fields.length){throw new Error("fieldNames and fields should be of the same length, if fieldNames is provided.")}params.fieldNames=params.fields.map(function(field,i){if(params.fieldNames&&typeof field==="string"){return params.fieldNames[i]}return typeof field==="string"?field:field.label||field.value});params.del=params.del||",";params.eol=params.eol||"";params.quotes=typeof params.quotes==="string"?params.quotes:'"';params.doubleQuotes=typeof params.doubleQuotes==="string"?params.doubleQuotes:Array(3).join(params.quotes);params.defaultValue=params.defaultValue;params.hasCSVColumnTitle=params.hasCSVColumnTitle!==false;params.includeEmptyRows=params.includeEmptyRows||false}function createColumnTitles(params){var str="";if(params.hasCSVColumnTitle){params.fieldNames.forEach(function(element){if(str!==""){str+=params.del}str+=JSON.stringify(element).replace(/\"/g,params.quotes)})}return str}function replaceQuotationMarks(stringifiedElement,quotes){var lastCharIndex=stringifiedElement.length-1;if(stringifiedElement[0]==='"'&&stringifiedElement[lastCharIndex]==='"'){var splitElement=stringifiedElement.split("");splitElement[0]=quotes;splitElement[lastCharIndex]=quotes;stringifiedElement=splitElement.join("")}return stringifiedElement}function createColumnContent(params,str){var dataRows=createDataRows(params);dataRows.forEach(function(dataElement){if(dataElement&&(Object.getOwnPropertyNames(dataElement).length>0||params.includeEmptyRows)){var line="";var eol=params.newLine||os.EOL||"\n";params.fields.forEach(function(fieldElement){var val;var defaultValue=params.defaultValue;if(typeof fieldElement==="object"&&"default"in fieldElement){defaultValue=fieldElement.default}if(fieldElement&&(typeof fieldElement==="string"||typeof fieldElement.value==="string")){var path=typeof fieldElement==="string"?fieldElement:fieldElement.value;val=lodashGet(dataElement,path,defaultValue)}else if(fieldElement&&typeof fieldElement.value==="function"){var field={label:fieldElement.label,default:fieldElement.default};val=fieldElement.value(dataElement,field,params.data)}if(val===null||val===undefined){val=defaultValue}if(val!==undefined){var stringifiedElement=JSON.stringify(val);if(typeof val==="object")stringifiedElement=JSON.stringify(stringifiedElement);if(params.quotes!=='"'){stringifiedElement=replaceQuotationMarks(stringifiedElement,params.quotes)}stringifiedElement=stringifiedElement.replace(/\\\\/g,"\\");if(params.excelStrings&&typeof val==="string"){stringifiedElement='"="'+stringifiedElement+'""'}line+=stringifiedElement}line+=params.del});line=line.substring(0,line.length-params.del.length);line=line.split("\\\\").map(function(portion){return portion.replace(/\\"/g,params.doubleQuotes)}).join("\\\\");line=line.replace(/\\\\/g,"\\");if(str!==""){str+=eol+line+params.eol}else{str=line+params.eol}}});return str}function createDataRows(params){var dataRows=params.data;if(params.unwindPath){dataRows=[];params.data.forEach(function(dataEl){var unwindArray=lodashGet(dataEl,params.unwindPath);var isArr=Array.isArray(unwindArray);if(isArr&&unwindArray.length){unwindArray.forEach(function(unwindEl){var dataCopy=lodashCloneDeep(dataEl);lodashSet(dataCopy,params.unwindPath,unwindEl);dataRows.push(dataCopy)})}else if(isArr&&!unwindArray.length){var dataCopy=lodashCloneDeep(dataEl);lodashSet(dataCopy,params.unwindPath,undefined);dataRows.push(dataCopy)}else{dataRows.push(dataEl)}})}return dataRows}}).call(exports,__webpack_require__(1))},function(module,exports){var process=module.exports={};var cachedSetTimeout;var cachedClearTimeout;function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}(function(){try{if(typeof setTimeout==="function"){cachedSetTimeout=setTimeout}else{cachedSetTimeout=defaultSetTimout}}catch(e){cachedSetTimeout=defaultSetTimout}try{if(typeof clearTimeout==="function"){cachedClearTimeout=clearTimeout}else{cachedClearTimeout=defaultClearTimeout}}catch(e){cachedClearTimeout=defaultClearTimeout}})();function runTimeout(fun){if(cachedSetTimeout===setTimeout){return setTimeout(fun,0)}if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout){cachedSetTimeout=setTimeout;return setTimeout(fun,0)}try{return cachedSetTimeout(fun,0)}catch(e){try{return cachedSetTimeout.call(null,fun,0)}catch(e){return cachedSetTimeout.call(this,fun,0)}}}function runClearTimeout(marker){if(cachedClearTimeout===clearTimeout){return clearTimeout(marker)}if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout){cachedClearTimeout=clearTimeout;return clearTimeout(marker)}try{return cachedClearTimeout(marker)}catch(e){try{return cachedClearTimeout.call(null,marker)}catch(e){return cachedClearTimeout.call(this,marker)}}}var queue=[];var draining=false;var currentQueue;var queueIndex=-1;function cleanUpNextTick(){if(!draining||!currentQueue){return}draining=false;if(currentQueue.length){queue=currentQueue.concat(queue)}else{queueIndex=-1}if(queue.length){drainQueue()}}function drainQueue(){if(draining){return}var timeout=runTimeout(cleanUpNextTick);draining=true;var len=queue.length;while(len){currentQueue=queue;queue=[];while(++queueIndex1){for(var i=1;i-1}function listCacheSet(key,value){var data=this.__data__,index=assocIndexOf(data,key);if(index<0){data.push([key,value])}else{data[index][1]=value}return this}ListCache.prototype.clear=listCacheClear;ListCache.prototype["delete"]=listCacheDelete;ListCache.prototype.get=listCacheGet;ListCache.prototype.has=listCacheHas;ListCache.prototype.set=listCacheSet;function MapCache(entries){var index=-1,length=entries?entries.length:0;this.clear();while(++index0&&predicate(value)){if(depth>1){baseFlatten(value,depth-1,predicate,isStrict,result)}else{arrayPush(result,value)}}else if(!isStrict){result[result.length]=value}}return result}function isFlattenable(value){return isArray(value)||isArguments(value)||!!(spreadableSymbol&&value&&value[spreadableSymbol])}function flatten(array){var length=array?array.length:0;return length?baseFlatten(array,1):[]}function isArguments(value){return isArrayLikeObject(value)&&hasOwnProperty.call(value,"callee")&&(!propertyIsEnumerable.call(value,"callee")||objectToString.call(value)==argsTag)}var isArray=Array.isArray;function isArrayLike(value){return value!=null&&isLength(value.length)&&!isFunction(value)}function isArrayLikeObject(value){return isObjectLike(value)&&isArrayLike(value)}function isFunction(value){var tag=isObject(value)?objectToString.call(value):"";return tag==funcTag||tag==genTag}function isLength(value){return typeof value=="number"&&value>-1&&value%1==0&&value<=MAX_SAFE_INTEGER}function isObject(value){var type=typeof value;return!!value&&(type=="object"||type=="function")}function isObjectLike(value){return!!value&&typeof value=="object"}module.exports=flatten}).call(exports,function(){return this}())},function(module,exports){(function(global){var LARGE_ARRAY_SIZE=200;var HASH_UNDEFINED="__lodash_hash_undefined__";var INFINITY=1/0;var funcTag="[object Function]",genTag="[object GeneratorFunction]";var reRegExpChar=/[\\^$.*+?()[\]{}|]/g;var reIsHostCtor=/^\[object .+?Constructor\]$/;var freeGlobal=typeof global=="object"&&global&&global.Object===Object&&global;var freeSelf=typeof self=="object"&&self&&self.Object===Object&&self;var root=freeGlobal||freeSelf||Function("return this")();function arrayIncludes(array,value){var length=array?array.length:0;return!!length&&baseIndexOf(array,value,0)>-1}function arrayIncludesWith(array,value,comparator){var index=-1,length=array?array.length:0;while(++index-1}function listCacheSet(key,value){var data=this.__data__,index=assocIndexOf(data,key);if(index<0){data.push([key,value])}else{data[index][1]=value}return this}ListCache.prototype.clear=listCacheClear;ListCache.prototype["delete"]=listCacheDelete;ListCache.prototype.get=listCacheGet;ListCache.prototype.has=listCacheHas;ListCache.prototype.set=listCacheSet;function MapCache(entries){var index=-1,length=entries?entries.length:0;this.clear();while(++index=LARGE_ARRAY_SIZE){var set=iteratee?null:createSet(array);if(set){return setToArray(set)}isCommon=false;includes=cacheHas;seen=new SetCache}else{seen=iteratee?[]:result}outer:while(++index-1}function listCacheSet(key,value){var data=this.__data__,index=assocIndexOf(data,key);if(index<0){data.push([key,value])}else{data[index][1]=value}return this}ListCache.prototype.clear=listCacheClear;ListCache.prototype["delete"]=listCacheDelete;ListCache.prototype.get=listCacheGet;ListCache.prototype.has=listCacheHas;ListCache.prototype.set=listCacheSet;function MapCache(entries){var index=-1,length=entries?entries.length:0;this.clear();while(++index-1&&value%1==0&&value-1}function listCacheSet(key,value){var data=this.__data__,index=assocIndexOf(data,key);if(index<0){data.push([key,value])}else{data[index][1]=value}return this}ListCache.prototype.clear=listCacheClear;ListCache.prototype["delete"]=listCacheDelete;ListCache.prototype.get=listCacheGet;ListCache.prototype.has=listCacheHas;ListCache.prototype.set=listCacheSet;function MapCache(entries){var index=-1,length=entries?entries.length:0;this.clear();while(++index-1&&value%1==0&&value-1&&value%1==0&&value<=MAX_SAFE_INTEGER}function isObject(value){var type=typeof value;return!!value&&(type=="object"||type=="function")}function isObjectLike(value){return!!value&&typeof value=="object"}function keys(object){return isArrayLike(object)?arrayLikeKeys(object):baseKeys(object)}function stubArray(){return[]}function stubFalse(){return false}module.exports=cloneDeep}).call(exports,function(){return this}(),__webpack_require__(8)(module))},function(module,exports){module.exports=function(module){if(!module.webpackPolyfill){module.deprecate=function(){};module.paths=[];module.children=[];module.webpackPolyfill=1}return module}},function(module,exports,__webpack_require__){var isBuffer=__webpack_require__(10);var flat=module.exports=flatten;flatten.flatten=flatten;flatten.unflatten=unflatten;function flatten(target,opts){opts=opts||{};var delimiter=opts.delimiter||".";var maxDepth=opts.maxDepth;var output={};function step(object,prev,currentDepth){currentDepth=currentDepth?currentDepth:1;Object.keys(object).forEach(function(key){var value=object[key];var isarray=opts.safe&&Array.isArray(value);var type=Object.prototype.toString.call(value);var isbuffer=isBuffer(value);var isobject=type==="[object Object]"||type==="[object Array]";var newKey=prev?prev+delimiter+key:key;if(!isarray&&!isbuffer&&isobject&&Object.keys(value).length&&(!opts.maxDepth||currentDepth0){key1=getkey(split.shift());key2=getkey(split[0])}}recipient[key1]=unflatten(target[key],opts)});return result}},function(module,exports){module.exports=function(obj){return obj!=null&&(isBuffer(obj)||isSlowBuffer(obj)||!!obj._isBuffer)};function isBuffer(obj){return!!obj.constructor&&typeof obj.constructor.isBuffer==="function"&&obj.constructor.isBuffer(obj)}function isSlowBuffer(obj){return typeof obj.readFloatLE==="function"&&typeof obj.slice==="function"&&isBuffer(obj.slice(0,0))}}])}); //# sourceMappingURL=json2csv.min.js.map