export-to-csv
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -1,1 +0,1 @@ | ||
export * from "./lib"; | ||
export * from "./lib/index.ts"; |
@@ -1,1 +0,1 @@ | ||
var v={fieldSeparator:",",decimalSeparator:".",quoteStrings:!0,quoteCharacter:'"',showTitle:!1,title:"My Generated Report",filename:"generated",showColumnHeaders:!0,useTextFile:!1,useBom:!0,columnHeaders:[],useKeysAsHeaders:!1,boolDisplay:{true:"TRUE",false:"FALSE"},replaceUndefinedWith:""},S="\r\n",T="\uFEFF",Z=(x)=>Object.assign({},v,x);class _ extends Error{constructor(x){super(x);this.name="CsvGenerationError"}}class q extends Error{constructor(x){super(x);this.name="EmptyHeadersError"}}class G extends Error{constructor(x){super(x);this.name="CsvDownloadEnvironmentError"}}var W=(x)=>x,z=(x)=>x,X=W,Y=W,Q=W,B=W;var m=function(x,A){if(A=='"'&&x.indexOf('"')>-1)return x.replace(/"/g,'""');return x},H=(x)=>typeof x==="object"?Q(x.key):Q(x),D=(x)=>typeof x==="object"?B(x.displayLabel):B(x),F=(x,...A)=>A.reduce(($,j)=>j($),x),K=(x)=>(A)=>x.useBom?X(z(A)+T):A,L=(x)=>(A)=>x.showTitle?X(z(A)+x.title):A,O=(x)=>(A)=>X(z(x)+z(A)+S),P=(x)=>(A,$)=>y(x)(Y(A+$)),y=(x)=>(A)=>W(z(A)+x.fieldSeparator),E=(x,A)=>($)=>{if(!x.showColumnHeaders)return $;if(A.length<1)throw new q("Option to show headers but none supplied. Make sure there are keys in your collection or that you've supplied headers through the config options.");let j=Y("");for(let I=0;I<A.length;I++){const N=D(A[I]);j=P(x)(j,b(x,N))}return j=Y(z(j).slice(0,-1)),O($)(j)},R=(x,A,$)=>(j)=>{let I=j;for(var N=0;N<$.length;N++){let U=Y("");for(let J=0;J<A.length;J++){const M=H(A[J]),C=typeof $[N][z(M)]==="undefined"?x.replaceUndefinedWith:$[N][z(M)];U=P(x)(U,b(x,C))}U=Y(z(U).slice(0,-1)),I=O(I)(U)}return I},h=z,V=(x)=>+x===x&&(!isFinite(x)||Boolean(x%1)),b=(x,A)=>{if(x.decimalSeparator==="locale"&&V(A))return A.toLocaleString();if(x.decimalSeparator!=="."&&V(A))return A.toString().replace(".",x.decimalSeparator);if(typeof A==="string"){let $=A;if(x.quoteStrings||x.fieldSeparator&&A.indexOf(x.fieldSeparator)>-1||x.quoteCharacter&&A.indexOf(x.quoteCharacter)>-1||A.indexOf("\n")>-1||A.indexOf("\r")>-1)$=x.quoteCharacter+m(A,x.quoteCharacter)+x.quoteCharacter;return $}if(typeof A==="boolean"&&x.boolDisplay){const $=A?"true":"false";return x.boolDisplay[$]}return A};var Ix=(x)=>(A)=>{const $=Z(x),j=$.useKeysAsHeaders?Object.keys(A[0]):$.columnHeaders;let I=F(X(""),K($),L($),E($,j),R($,j,A));if(z(I).length<1)throw new _("Output is empty. Is your data formatted correctly?");return I},Jx=(x)=>(A)=>{if(!window)throw new G("Downloading only supported in a browser environment.");const $=Z(x),j=z(A),I=$.useTextFile?"plain":"csv",N=$.useTextFile?"txt":"csv";let U=new Blob([j],{type:`text/${I};charset=utf8;`}),J=document.createElement("a");J.download=`${$.filename}.${N}`,J.href=URL.createObjectURL(U),J.setAttribute("visibility","hidden"),document.body.appendChild(J),J.click(),document.body.removeChild(J)};export{Z as mkConfig,Ix as generateCsv,Jx as download,h as asString}; | ||
var v={fieldSeparator:",",decimalSeparator:".",quoteStrings:!0,quoteCharacter:'"',showTitle:!1,title:"My Generated Report",filename:"generated",showColumnHeaders:!0,useTextFile:!1,useBom:!0,columnHeaders:[],useKeysAsHeaders:!1,boolDisplay:{true:"TRUE",false:"FALSE"},replaceUndefinedWith:""},B="\r\n",F="\uFEFF",Y=(x)=>Object.assign({},v,x);class Z extends Error{constructor(x){super(x);this.name="CsvGenerationError"}}class _ extends Error{constructor(x){super(x);this.name="EmptyHeadersError"}}class $ extends Error{constructor(x){super(x);this.name="CsvDownloadEnvironmentError"}}var U=(x)=>x,z=(x)=>x,W=U,X=U,Q=U,T=U;var w=function(x,A){if(A=='"'&&x.indexOf('"')>-1)return x.replace(/"/g,'""');return x},H=(x)=>typeof x==="object"?Q(x.key):Q(x),D=(x)=>typeof x==="object"?T(x.displayLabel):T(x),V=(x,...A)=>A.reduce((N,j)=>j(N),x),K=(x)=>(A)=>x.useBom?W(z(A)+F):A,L=(x)=>(A)=>x.showTitle?W(z(A)+x.title):A,P=(x)=>(A)=>W(z(x)+z(A)+B),R=(x)=>(A,N)=>h(x)(X(A+N)),h=(x)=>(A)=>U(z(A)+x.fieldSeparator),E=(x,A)=>(N)=>{if(!x.showColumnHeaders)return N;if(A.length<1)throw new _("Option to show headers but none supplied. Make sure there are keys in your collection or that you've supplied headers through the config options.");let j=X("");for(let G=0;G<A.length;G++){const J=D(A[G]);j=R(x)(j,C(x,J))}return j=X(z(j).slice(0,-1)),P(N)(j)},O=(x,A,N)=>(j)=>{let G=j;for(var J=0;J<N.length;J++){let S=X("");for(let I=0;I<A.length;I++){const q=H(A[I]),b=typeof N[J][z(q)]==="undefined"?x.replaceUndefinedWith:N[J][z(q)];S=R(x)(S,C(x,b))}S=X(z(S).slice(0,-1)),G=P(G)(S)}return G},y=z,M=(x)=>+x===x&&(!isFinite(x)||Boolean(x%1)),C=(x,A)=>{if(x.decimalSeparator==="locale"&&M(A))return A.toLocaleString();if(x.decimalSeparator!=="."&&M(A))return A.toString().replace(".",x.decimalSeparator);if(typeof A==="string"){let N=A;if(x.quoteStrings||x.fieldSeparator&&A.indexOf(x.fieldSeparator)>-1||x.quoteCharacter&&A.indexOf(x.quoteCharacter)>-1||A.indexOf("\n")>-1||A.indexOf("\r")>-1)N=x.quoteCharacter+w(A,x.quoteCharacter)+x.quoteCharacter;return N}if(typeof A==="boolean"&&x.boolDisplay){const N=A?"true":"false";return x.boolDisplay[N]}return A};var Gx=(x)=>(A)=>{const N=Y(x),j=N.useKeysAsHeaders?Object.keys(A[0]):N.columnHeaders;let G=V(W(""),K(N),L(N),E(N,j),O(N,j,A));if(z(G).length<1)throw new Z("Output is empty. Is your data formatted correctly?");return G},Ix=(x)=>(A)=>{if(!window)throw new $("Downloading only supported in a browser environment.");const N=Y(x),j=z(A),G=N.useTextFile?"plain":"csv",J=N.useTextFile?"txt":"csv";let S=new Blob([j],{type:`text/${G};charset=utf8;`}),I=document.createElement("a");I.download=`${N.filename}.${J}`,I.href=URL.createObjectURL(S),I.setAttribute("visibility","hidden"),document.body.appendChild(I),I.click(),document.body.removeChild(I)};export{Y as mkConfig,Gx as generateCsv,Ix as download,y as asString}; |
@@ -1,2 +0,2 @@ | ||
import { WithDefaults, ConfigOptions } from "./types"; | ||
import { WithDefaults, ConfigOptions } from "./types.ts"; | ||
export declare const defaults: WithDefaults<ConfigOptions>; | ||
@@ -3,0 +3,0 @@ export declare const endOfLine = "\r\n"; |
/// <reference lib="dom" /> | ||
import { CsvOutput, ConfigOptions, IO } from "./types"; | ||
import { CsvOutput, ConfigOptions, IO } from "./types.ts"; | ||
/** | ||
@@ -4,0 +4,0 @@ * |
@@ -1,2 +0,2 @@ | ||
import { ColumnHeader, ConfigOptions, CsvOutput, CsvRow, Newtype, WithDefaults } from "./types"; | ||
import { ColumnHeader, ConfigOptions, CsvOutput, CsvRow, Newtype, WithDefaults } from "./types.ts"; | ||
export declare const thread: <T>(initialValue: T, ...fns: Array<Function>) => T; | ||
@@ -3,0 +3,0 @@ export declare const addBOM: (config: WithDefaults<ConfigOptions>) => (output: CsvOutput) => CsvOutput; |
@@ -1,4 +0,4 @@ | ||
export * from "./generator"; | ||
export { mkConfig } from "./config"; | ||
export { CsvOutput, ConfigOptions, ColumnHeader } from "./types"; | ||
export { asString } from "./helpers"; | ||
export * from "./generator.ts"; | ||
export { mkConfig } from "./config.ts"; | ||
export { CsvOutput, ConfigOptions, ColumnHeader } from "./types.ts"; | ||
export { asString } from "./helpers.ts"; |
{ | ||
"name": "export-to-csv", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Easily create CSV data from json collection", | ||
@@ -8,6 +8,6 @@ "type": "module", | ||
"type": "git", | ||
"url": "https://github.com/alexcaza/export-to-csv.git" | ||
"url": "git+https://github.com/alexcaza/export-to-csv.git" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf output && bun build index.ts --outdir ./output --minify && tsc index.ts --declaration --emitDeclarationOnly --outdir ./output", | ||
"build": "rm -rf output && bun build index.ts --outdir ./output --minify && tsc", | ||
"e2e": "rm -rf integration/export-to-csv.js && bun run build && cp output/index.js integration/export-to-csv.js && playwright test", | ||
@@ -36,4 +36,7 @@ "e2e-ci": "rm -rf integration/export-to-csv.js && bun run build && cp output/index.js integration/export-to-csv.js && bunx playwright install --with-deps && playwright test", | ||
}, | ||
"main": "./output/index.js", | ||
"exports": "./output/index.js", | ||
"types": "./output/index.d.ts", | ||
"engines": { | ||
"node": "^v12.20.0 || >=v14.13.0" | ||
}, | ||
"homepage": "https://github.com/alexcaza/export-to-csv#readme", | ||
@@ -40,0 +43,0 @@ "devDependencies": { |
@@ -19,3 +19,3 @@ # export-to-csv | Export to CSV Mini Library | ||
You can easily use this library in JavaScript as well. The bundle is using ES6 modules, which all modern browsers support. | ||
You can easily use this library in JavaScript as well. The bundle uses ES modules, which all modern browsers support. | ||
@@ -22,0 +22,0 @@ You can also look at the [integration tests](integration/index.html) for browser/JS use, and the [unit tests](lib/__specs__) to understand how the library functions. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22699
13