UNPKG

@simuratli/react-json-csv-converter

Version:
12 lines (11 loc) 8.24 kB
"use strict";var e=require("react"),r=function(){return r=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var t,n={exports:{}},o={};var a,c,i={}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */function l(){return a||(a=1,"production"!==process.env.NODE_ENV&&function(){function r(e){if(null==e)return null;if("function"==typeof e)return e.$$typeof===_?null:e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case d:return"Fragment";case b:return"Profiler";case m:return"StrictMode";case k:return"Suspense";case j:return"SuspenseList";case w:return"Activity"}if("object"==typeof e)switch("number"==typeof e.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case y:return"Portal";case g:return(e.displayName||"Context")+".Provider";case v:return(e._context.displayName||"Context")+".Consumer";case h:var t=e.render;return(e=e.displayName)||(e=""!==(e=t.displayName||t.name||"")?"ForwardRef("+e+")":"ForwardRef"),e;case S:return null!==(t=e.displayName||null)?t:r(e.type)||"Memo";case O:t=e._payload,e=e._init;try{return r(e(t))}catch(e){}}return null}function t(e){return""+e}function n(e){try{t(e);var r=!1}catch(e){r=!0}if(r){var n=(r=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),t(e)}}function o(e){if(e===d)return"<>";if("object"==typeof e&&null!==e&&e.$$typeof===O)return"<...>";try{var t=r(e);return t?"<"+t+">":"<...>"}catch(e){return"<...>"}}function a(){return Error("react-stack-top-frame")}function c(){var e=r(this.type);return T[e]||(T[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(e=this.props.ref)?e:null}function l(e,t,o,a,i,l,f,y){var d,m=t.children;if(void 0!==m)if(a)if(x(m)){for(a=0;a<m.length;a++)s(m[a]);Object.freeze&&Object.freeze(m)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else s(m);if(E.call(t,"key")){m=r(e);var b=Object.keys(t).filter((function(e){return"key"!==e}));a=0<b.length?"{key: someKey, "+b.join(": ..., ")+": ...}":"{key: someKey}",C[m+a]||(b=0<b.length?"{"+b.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',a,m,b,m),C[m+a]=!0)}if(m=null,void 0!==o&&(n(o),m=""+o),function(e){if(E.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(t)&&(n(t.key),m=""+t.key),"key"in t)for(var v in o={},t)"key"!==v&&(o[v]=t[v]);else o=t;return m&&function(e,r){function t(){u||(u=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(o,"function"==typeof e?e.displayName||e.name||"Unknown":e),function(e,r,t,n,o,a,i,l){return t=a.ref,e={$$typeof:p,type:e,key:r,props:a,_owner:o},null!==(void 0!==t?t:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:c}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:l}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(e,m,l,0,null===(d=N.A)?null:d.getOwner(),o,f,y)}function s(e){"object"==typeof e&&null!==e&&e.$$typeof===p&&e._store&&(e._store.validated=1)}var u,f=e,p=Symbol.for("react.transitional.element"),y=Symbol.for("react.portal"),d=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),b=Symbol.for("react.profiler"),v=Symbol.for("react.consumer"),g=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),k=Symbol.for("react.suspense"),j=Symbol.for("react.suspense_list"),S=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),w=Symbol.for("react.activity"),_=Symbol.for("react.client.reference"),N=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,E=Object.prototype.hasOwnProperty,x=Array.isArray,R=console.createTask?console.createTask:function(){return null},T={},A=(f={"react-stack-bottom-frame":function(e){return e()}})["react-stack-bottom-frame"].bind(f,a)(),P=R(o(a)),C={};i.Fragment=d,i.jsx=function(e,r,t,n,a){var c=1e4>N.recentlyCreatedOwnerStacks++;return l(e,r,t,!1,0,a,c?Error("react-stack-top-frame"):A,c?R(o(e)):P)},i.jsxs=function(e,r,t,n,a){var c=1e4>N.recentlyCreatedOwnerStacks++;return l(e,r,t,!0,0,a,c?Error("react-stack-top-frame"):A,c?R(o(e)):P)}}()),i}var s=(c||(c=1,"production"===process.env.NODE_ENV?n.exports=function(){if(t)return o;t=1;var e=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(r,t,n){var o=null;if(void 0!==n&&(o=""+n),void 0!==t.key&&(o=""+t.key),"key"in t)for(var a in n={},t)"key"!==a&&(n[a]=t[a]);else n=t;return t=n.ref,{$$typeof:e,type:r,key:o,ref:void 0!==t?t:null,props:n}}return o.Fragment=r,o.jsx=n,o.jsxs=n,o}():n.exports=l()),n.exports);exports.JsonToCsvDownload=function(e){var t=e.data,n=void 0===t?[]:t,o=e.headers,a=void 0===o?null:o,c=e.filename,i=void 0===c?"data.csv":c,l=e.className,u=void 0===l?"":l,f=e.children,p=void 0===f?"Download CSV":f,y=e.onDownload,d=void 0===y?function(){}:y,m=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(t[n[o]]=e[n[o]])}return t}(e,["data","headers","filename","className","children","onDownload"]);return s.jsx("button",r({onClick:function(){try{if(!Array.isArray(n)||0===n.length)return void console.warn("JsonToCsvDownload: No data provided or data is empty");var e=[],r=[];if(a&&a.length>0?(r=a.map((function(e){return e.label})),e=a.map((function(e){return e.key}))):r=function(e,r,t){if(t||2===arguments.length)for(var n,o=0,a=r.length;o<a;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return e.concat(n||Array.prototype.slice.call(r))}([],e=function(e){if(!Array.isArray(e)||0===e.length)return[];var r=new Set;return e.forEach((function(e){"object"==typeof e&&null!==e&&Object.keys(e).forEach((function(e){return r.add(e)}))})),Array.from(r)}(n),!0),0===e.length)return void console.warn("JsonToCsvDownload: No keys found");var t=[];t.push(r),n.forEach((function(r){var n=e.map((function(e){var t=r[e];return null==t?"":"string"==typeof t&&(t.includes(",")||t.includes('"')||t.includes("\n"))?'"'.concat(t.replace(/"/g,'""'),'"'):String(t)}));t.push(n)}));var o=t.map((function(e){return e.join(",")})).join("\n"),c=new Blob([o],{type:"text/csv;charset=utf-8;"}),l=URL.createObjectURL(c),s=document.createElement("a");s.href=l,s.setAttribute("download",i),document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(l),d()}catch(e){console.error("JsonToCsvDownload: Error generating CSV",e)}},className:u},m,{children:p}))}; //# sourceMappingURL=index.js.map