xl1 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # xl1
2
+
3
+ some dev script sample
package/bin/cli.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('../dist/')
package/dist/index.js ADDED
@@ -0,0 +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()();
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "xl1",
3
+ "version": "0.0.1",
4
+ "description": "just some xlsx script.",
5
+ "bin": {
6
+ "xl1": "bin/cli.js"
7
+ },
8
+ "files": [
9
+ "dist",
10
+ "bin",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "run": "node bin/cli.js"
15
+ },
16
+ "keywords": [],
17
+ "author": "exia.huang",
18
+ "dependencies": {
19
+ "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
20
+ "yargs": "^17.7.2"
21
+ }
22
+ }