xl1 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var x=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var p=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var b=p((W,k)=>{var y=x("fs"),l=x("xlsx"),F=s=>{let{file:e,sheet:r,range:a,defval:c}=s;if(!y.existsSync(e)){console.log("file not found, ",e);return}if(![".xlsx"].find(m=>e.endsWith(m))){console.log("file type error, ",e);return}let o=l.readFile(e,{bookSheets:!1});if(!o)return null;let g=o.Sheets[r||o.SheetNames[0]],d={range:a,blankrows:!1,defval:c};return l.utils.sheet_to_json(g,d)},E=s=>{let{file:e,data:r,sheet:a}=s;if(!(e&&r&&Array.isArray(r)&&r.length>0))return;let c=Array.isArray(r[0])?l.utils.aoa_to_sheet(r):l.utils.json_to_sheet(r),o=y.existsSync(e)?l.readFile(e,{cellDates:!0}):l.utils.book_new();l.utils.book_append_sheet(o,c,a?a.substring(0,31):"Sheet1",!0),l.writeFile(o,e,{compression:!0})};k.exports={readXlsx:F,writeXlsx:E}});var _=p((B,w)=>{var{readXlsx:M}=b(),N={command:"read",describe:"load excel file",builder:{file:{alias:"f",describe:"load xlsx file ",demandOption:!0,type:"string"},sheet:{alias:"s",describe:"xlsx sheet name",demandOption:!1,type:"string"},range:{alias:"r",describe:"range of excel",default:"A1:Z2000",demandOption:!1,type:"string"},defval:{describe:"defval of cell",demandOption:!1,default:void 0,type:"string"}},handler(s){(async()=>{let e=M(s);console.log(JSON.stringify(e,null,2))})()}};w.exports=N});var O=p((H,S)=>{var{readXlsx:A,writeXlsx:Z}=b(),D={command:"merge <files..>",describe:"merge multiple excel sheets into the first sheet. (format: file|sheet|range, file|Sheet1|A1:Z2000)",builder:{output:{alias:"o",describe:"output file name",default:"MergedBook.xlsx",type:"string"},sheet:{alias:"s",describe:"xlsx sheet name",demandOption:!1,type:"string"}},handler(s){(async()=>{let e=t=>{let[n,i,f]=t.split("|");return{file:n,sheet:i,range:f||"A1:Z2000",defval:null}},[r,...a]=s.files,c=e(r),o=a.map(e),u=A(c),g=o.map(t=>A(t)),d=t=>{let n=Object.values(t);return n&&n.length>0?n[0]:""};g.forEach(t=>{u.forEach(n=>{let i=t.find(f=>d(f)===d(n)&&d(n));i&&Object.keys(i).slice(1).forEach(h=>{h in n&&i[h]!==null&&(n[h]=i[h])})})}),console.log("Merge completed successfully.");let m=Object.keys(u[0]).map(t=>t.startsWith("__EMPTY")?null:t),X=u.slice(1).map(t=>Object.values(t)).filter(t=>t.some(n=>n!==null)),j=[m,...X];Z({file:s.output,data:j,sheet:s.sheet||"MergedSheet"})})()}};S.exports=D});var v=p((J,q)=>{q.exports=()=>{let s=x("yargs").scriptName("xl1");s.command(_()),s.command(O());let e=s.parse();(!e._||e._.length===0)&&s.showHelp()}});v()();
1
+ "use strict";var S=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var b=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var w=b((P,q)=>{var O=S("fs"),r=S("xlsx"),R=s=>{let{file:e,sheet:o,range:a,defval:c,noNullRow:l}=s;if(!O.existsSync(e)){console.log("file not found, ",e);return}if(![".xlsx",".xlsm"].find(u=>e.endsWith(u))){console.log("file type error, ",e);return}let i=r.readFile(e,{bookSheets:!1});if(!i)return null;let g=i.Sheets[o||i.SheetNames[0]],k={range:a,blankrows:!1,defval:c},p=r.utils.sheet_to_json(g,k);return l?p.filter(u=>Object.values(u).some(x=>!!x)):p},Z=s=>{let{file:e,data:o,sheet:a}=s;if(!(e&&o&&Array.isArray(o)&&o.length>0))return;let c=Array.isArray(o[0])?r.utils.aoa_to_sheet(o):r.utils.json_to_sheet(o),l=O.existsSync(e)?r.readFile(e,{cellDates:!0}):r.utils.book_new();r.utils.book_append_sheet(l,c,a?a.substring(0,31):"Sheet1",!0),r.writeFile(l,e,{compression:!0})};q.exports={readXlsx:R,writeXlsx:Z}});var v=b((T,j)=>{var{readXlsx:D}=w(),W={command:"read",describe:"load excel file",builder:{file:{alias:"f",describe:"load xlsx file ",demandOption:!0,type:"string"},sheet:{alias:"s",describe:"xlsx sheet name",demandOption:!1,type:"string"},range:{alias:"r",describe:"range of excel",default:"A1:Z2000",demandOption:!1,type:"string"},defval:{describe:"defval of cell",demandOption:!1,default:void 0,type:"string"}},handler(s){(async()=>{let e=D(s);console.log(JSON.stringify(e,null,2))})()}};j.exports=W});var F=b((Y,X)=>{var{readXlsx:I,writeXlsx:B}=w(),H={command:"merge <files..>",describe:"merge multiple excel sheets into the first sheet. (format: file|sheet|range, file|Sheet1|A1:Z2000)",builder:{output:{alias:"o",describe:"output file name",default:"MergedBook.xlsx",type:"string"},sheet:{alias:"s",describe:"xlsx sheet name",demandOption:!1,type:"string"},debug:{alias:"d",describe:"print debug log",demandOption:!1,type:"boolean"}},handler(s){(async()=>{let e=t=>{let[n,_,f]=t.split("|");return{file:n,sheet:_,range:f||"A1:Z2000",defval:null,noNullRow:!0}},[o,...a]=s.files,c=e(o),l=a.map(e),i=t=>{let n=Object.values(t);return n&&n.length>0?n[0]:""},d=I(c),g=d.map(i);l.map(t=>I(t)).forEach((t,n)=>{t.map(i).forEach((f,M)=>{let y=g.findIndex(h=>f&&f===h);if(y>-1){let h=t[M],A=d[y];Object.keys(h).slice(1).forEach(m=>{m in A&&h[m]&&(A[m]=h[m])})}s.debug&&console.log(l[n].sheet,f,y>-1?"found in baseSheet":"not found in baseSheet")})}),console.log("Merge completed successfully.");let p=Object.keys(d[0]).map(t=>t.startsWith("__EMPTY")?null:t),u=d.slice(1).map(t=>Object.values(t)).filter(t=>t.some(n=>n!==null)),x=[p,...u];B({file:s.output,data:x,sheet:s.sheet||"MergedSheet"})})()}};X.exports=H});var E=b((z,N)=>{N.exports=()=>{let s=S("yargs").scriptName("xl1");s.command(v()),s.command(F());let e=s.parse();(!e._||e._.length===0)&&s.showHelp()}});E()();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xl1",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "just some xlsx script.",
5
5
  "bin": {
6
6
  "xl1": "bin/cli.js"