3 lines
53 KiB
JavaScript
3 lines
53 KiB
JavaScript
|
(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.defa
|
||
|
assignValue(nested,key,newValue);nested=nested[key]}return object}function baseToString(value){if(typeof value=="string"){return value}if(isSymbol(value)){return symbolToString?symbolToString.call(value):""}var result=value+"";return result=="0"&&1/value==-INFINITY?"-0":result}function castPath(value){return isArray(value)?value:stringToPath(value)}function getMapData(map,key){var data=map.__data__;return isKeyable(key)?data[typeof key=="string"?"string":"hash"]:data.map}function getNative(object,key){var value=getValue(object,key);return baseIsNative(value)?value:undefined}function isIndex(value,length){length=length==null?MAX_SAFE_INTEGER:length;return!!length&&(typeof value=="number"||reIsUint.test(value))&&(value>-1&&value%1==0&&value<length)}function isKey(value,object){if(isArray(value)){return false}var type=typeof value;if(type=="number"||type=="symbol"||type=="boolean"||value==null||isSymbol(value)){return true}return reIsPlainProp.test(value)||!reIsDeepProp.test(value)||object!=null&&value in Object(object)}function isKeyable(value){var type=typeof value;return type=="string"||type=="number"||type=="symbol"||type=="boolean"?value!=="__proto__":value===null}function isMasked(func){return!!maskSrcKey&&maskSrcKey in func}var stringToPath=memoize(function(string){string=toString(string);var result=[];if(reLeadingDot.test(string)){result.push("")}string.replace(rePropName,function(match,number,quote,string){result.push(quote?string.replace(reEscapeChar,"$1"):number||match)});return result});function toKey(value){if(typeof value=="string"||isSymbol(value)){return value}var result=value+"";return result=="0"&&1/value==-INFINITY?"-0":result}function toSource(func){if(func!=null){try{return funcToString.call(func)}catch(e){}try{return func+""}catch(e){}}return""}function memoize(func,resolver){if(typeof func!="function"||resolver&&typeof resolver!="function"){throw new TypeError(FUNC_ERROR_TEXT)}var memoized=function(){var args=arguments,key=resolver?resolver.apply(this,args):args[0],cache=memoized.cache;if(cache.has(key)){return cache.get(key)}var result=func.apply(this,args);memoized.cache=cache.set(key,result);return result};memoized.cache=new(memoize.Cache||MapCache);return memoized}memoize.Cache=MapCache;function eq(value,other){return value===other||value!==value&&other!==other}var isArray=Array.isArray;function isFunction(value){var tag=isObject(value)?objectToString.call(value):"";return tag==funcTag||tag==genTag}function isObject(value){var type=typeof value;return!!value&&(type=="object"||type=="function")}function isObjectLike(value){return!!value&&typeof value=="object"}function isSymbol(value){return typeof value=="symbol"||isObjectLike(value)&&objectToString.call(value)==symbolTag}function toString(value){return value==null?"":baseToString(value)}function set(object,path,value){return object==null?object:baseSet(object,path,value)}module.exports=set}).call(exports,function(){return this}())},function(module,exports,__webpack_require__){(function(global,module){var LARGE_ARRAY_SIZE=200;var HASH_UNDEFINED="__lodash_hash_undefined__";var MAX_SAFE_INTEGER=9007199254740991;var argsTag="[object Arguments]",arrayTag="[object Array]",boolTag="[object Boolean]",dateTag="[object Date]",errorTag="[object Error]",funcTag="[object Function]",genTag="[object GeneratorFunction]",mapTag="[object Map]",numberTag="[object Number]",objectTag="[object Object]",promiseTag="[object Promise]",regexpTag="[object RegExp]",setTag="[object Set]",stringTag="[object String]",symbolTag="[object Symbol]",weakMapTag="[object WeakMap]";var arrayBufferTag="[object ArrayBuffer]",dataViewTag="[object DataView]",float32Tag="[object Float32Array]",float64Tag="[object Float64Array]",int8Tag="[object Int8Array]",int16Tag="[object Int16Array]",int32Tag="[object Int32Array]",uint8Tag="[object Uint8Array]",uint8ClampedTag="[object Uint8ClampedArray]",uint16Tag="[object Uint16Array]",uint32Tag="[object Uint32Array]";var reRegExpChar=/[\\^$.*+?()[\]{}|]/g;var reFlags=/\w*$/;var reIsHostCtor=/^\[object .+?Constructor\]$/;var reIsUint=/^(?:0|[1-9]\d*)
|
||
|
//# sourceMappingURL=json2csv.min.js.map
|