@vdhewei/xlsx-template-lib 1.2.4 → 1.3.0
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/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +50 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1998,6 +1998,7 @@ var exprIndex = `index`;
|
|
|
1998
1998
|
var defaultKey = `!!`;
|
|
1999
1999
|
var numberKey = `!!number`;
|
|
2000
2000
|
var codeKey = `!!codeKey`;
|
|
2001
|
+
var codeAliasKey = `!!codeAliasKey`;
|
|
2001
2002
|
var funcCommand = "fn:";
|
|
2002
2003
|
var RuleToken = /* @__PURE__ */ ((RuleToken2) => {
|
|
2003
2004
|
RuleToken2["AliasToken"] = "alias";
|
|
@@ -2053,16 +2054,16 @@ var RuleMapOptions = class _RuleMapOptions {
|
|
|
2053
2054
|
}
|
|
2054
2055
|
parseDefault(worksheet) {
|
|
2055
2056
|
this.ruleKeyMap = mergeOption(this.ruleKeyMap, defaultRuleTokenMap);
|
|
2056
|
-
if (this.startLine === void 0) {
|
|
2057
|
+
if (this.startLine === void 0 || isNaN(this.startLine) || this.startLine < 0) {
|
|
2057
2058
|
this.startLine = 1;
|
|
2058
2059
|
}
|
|
2059
|
-
if (this.endLine === void 0) {
|
|
2060
|
+
if (this.endLine === void 0 || isNaN(this.endLine) || this.endLine < 0) {
|
|
2060
2061
|
this.endLine = worksheet.rowCount;
|
|
2061
2062
|
}
|
|
2062
|
-
if (this.startColumn === void 0) {
|
|
2063
|
+
if (this.startColumn === void 0 || isNaN(this.startColumn) || this.startColumn < 0) {
|
|
2063
2064
|
this.startColumn = 1;
|
|
2064
2065
|
}
|
|
2065
|
-
if (this.endColumn === void 0) {
|
|
2066
|
+
if (this.endColumn === void 0 || isNaN(this.endColumn) || this.endColumn < 0) {
|
|
2066
2067
|
this.endColumn = worksheet.columnCount;
|
|
2067
2068
|
}
|
|
2068
2069
|
return this;
|
|
@@ -2970,7 +2971,7 @@ var resolveCompileMacroGen = (ctx, expr, currentCellIndex) => {
|
|
|
2970
2971
|
var getExprEnd = function(macroExpr, matchIndex, rparenToken) {
|
|
2971
2972
|
return macroExpr.indexOf(rparenToken, matchIndex);
|
|
2972
2973
|
};
|
|
2973
|
-
var macroFormatters = [numberKey, codeKey];
|
|
2974
|
+
var macroFormatters = [numberKey, codeKey, codeAliasKey];
|
|
2974
2975
|
var extractMacro = function(expr, options) {
|
|
2975
2976
|
let end = NaN;
|
|
2976
2977
|
const offset = options.startToken.length;
|
|
@@ -3009,9 +3010,17 @@ var __codeKey = (str) => {
|
|
|
3009
3010
|
var __numberKey = (str) => {
|
|
3010
3011
|
return Number.parseInt(str, 10).toString();
|
|
3011
3012
|
};
|
|
3013
|
+
var __codeAliasKey = (str) => {
|
|
3014
|
+
const key = __codeKey(str);
|
|
3015
|
+
if (key !== "") {
|
|
3016
|
+
return `${defaultRuleTokenParserMap.get("@" /* UseAliasToken */)}${key}`;
|
|
3017
|
+
}
|
|
3018
|
+
return "";
|
|
3019
|
+
};
|
|
3012
3020
|
var macroFormatter = /* @__PURE__ */ new Map([
|
|
3013
3021
|
[codeKey, __codeKey],
|
|
3014
3022
|
[numberKey, __numberKey],
|
|
3023
|
+
[codeAliasKey, __codeAliasKey],
|
|
3015
3024
|
[defaultKey, (v) => v]
|
|
3016
3025
|
]);
|
|
3017
3026
|
var execMacroFormat = function(value, formatter) {
|
|
@@ -3492,6 +3501,25 @@ var compileWorkSheetPlaceholder = function(ctx, sheet, result) {
|
|
|
3492
3501
|
}
|
|
3493
3502
|
return void 0;
|
|
3494
3503
|
};
|
|
3504
|
+
var loadCompileSheets = (workbook, ruleSheetName) => {
|
|
3505
|
+
let first;
|
|
3506
|
+
let sheets = [];
|
|
3507
|
+
for (const [_, w] of workbook.worksheets.entries()) {
|
|
3508
|
+
if (w.name === ruleSheetName) {
|
|
3509
|
+
continue;
|
|
3510
|
+
}
|
|
3511
|
+
if (first === "") {
|
|
3512
|
+
first = w.name;
|
|
3513
|
+
}
|
|
3514
|
+
if (!w.name.endsWith(".json") && !w.name.endsWith(".config")) {
|
|
3515
|
+
sheets.push(w.name);
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
if (sheets.length <= 0 && first !== "") {
|
|
3519
|
+
sheets.push(first);
|
|
3520
|
+
}
|
|
3521
|
+
return sheets;
|
|
3522
|
+
};
|
|
3495
3523
|
var compile = async function(data, ruleSheetName, options) {
|
|
3496
3524
|
const workbook = await loadWorkbook(data);
|
|
3497
3525
|
const sheet = workbook.getWorksheet(ruleSheetName);
|
|
@@ -3510,6 +3538,10 @@ var compile = async function(data, ruleSheetName, options) {
|
|
|
3510
3538
|
const excludes = [ruleSheetName];
|
|
3511
3539
|
options = RuleMapOptions.withAllSheets(workbook, excludes);
|
|
3512
3540
|
}
|
|
3541
|
+
options = options.parseDefault(sheet);
|
|
3542
|
+
if (options.compileSheets === void 0 || options.compileSheets.length === 0) {
|
|
3543
|
+
options.compileSheets = loadCompileSheets(workbook, ruleSheetName);
|
|
3544
|
+
}
|
|
3513
3545
|
const result = parseWorkSheetRules(sheet, options);
|
|
3514
3546
|
const errs = compileCheck(result, options);
|
|
3515
3547
|
if (errs !== void 0) {
|
|
@@ -3572,6 +3604,9 @@ var fetchAlias = (m) => {
|
|
|
3572
3604
|
};
|
|
3573
3605
|
var removeUnExportSheets = (w, options) => {
|
|
3574
3606
|
const removes = [];
|
|
3607
|
+
if (typeof options.skipRemoveUnExportSheet === "boolean" && options.skipRemoveUnExportSheet === true) {
|
|
3608
|
+
return w;
|
|
3609
|
+
}
|
|
3575
3610
|
if (options.compileSheets === void 0 || options.compileSheets.length <= 0) {
|
|
3576
3611
|
for (const [i, v] of w.worksheets.entries()) {
|
|
3577
3612
|
const sheetName = v.name;
|
|
@@ -3614,6 +3649,7 @@ ExprResolver.resolveCompileMacroGen = resolveCompileMacroGen;
|
|
|
3614
3649
|
ExprResolver.resolveCompileMacroExpr = resolveCompileMacroExpr;
|
|
3615
3650
|
|
|
3616
3651
|
// src/extends.ts
|
|
3652
|
+
import fs2 from "fs/promises";
|
|
3617
3653
|
function hasToString(obj) {
|
|
3618
3654
|
return obj != null && typeof obj.toString === "function";
|
|
3619
3655
|
}
|
|
@@ -3883,6 +3919,12 @@ var autoRegisterAlias = function(values, configure) {
|
|
|
3883
3919
|
values[aliasKey] = alias;
|
|
3884
3920
|
return values;
|
|
3885
3921
|
};
|
|
3922
|
+
var saveCompile = async (compileOptions, wb) => {
|
|
3923
|
+
if (typeof compileOptions.save === "boolean" && compileOptions.save === true && typeof compileOptions.saveFile === "string" && compileOptions.saveFile !== "") {
|
|
3924
|
+
const path2 = compileOptions.saveFile;
|
|
3925
|
+
await fs2.writeFile(`${path2}compile_${(/* @__PURE__ */ new Date()).valueOf()}.xlsx`, wb);
|
|
3926
|
+
}
|
|
3927
|
+
};
|
|
3886
3928
|
var generateCommandsXlsxTemplateWithCompile = async function(data, values, compileOptions, options) {
|
|
3887
3929
|
if (compileOptions.sheetName === void 0 || compileOptions.sheetName === "") {
|
|
3888
3930
|
compileOptions.sheetName = compileRuleSheetName;
|
|
@@ -3894,6 +3936,7 @@ var generateCommandsXlsxTemplateWithCompile = async function(data, values, compi
|
|
|
3894
3936
|
values = autoRegisterAlias(values, result.configure);
|
|
3895
3937
|
result.workbook = ExprResolver.removeUnExportSheets(result.workbook, compileOptions);
|
|
3896
3938
|
const wb = await ExprResolver.toBuffer(result.workbook);
|
|
3939
|
+
await saveCompile(compileOptions, wb);
|
|
3897
3940
|
const w = await Workbook.parse(wb, options);
|
|
3898
3941
|
w.setQueryFunctionHandler(commandExtendQuery);
|
|
3899
3942
|
await w.substituteAll(values);
|
|
@@ -3932,6 +3975,7 @@ export {
|
|
|
3932
3975
|
hasGeneratorToken,
|
|
3933
3976
|
isRuleToken,
|
|
3934
3977
|
isUrl,
|
|
3978
|
+
loadCompileSheets,
|
|
3935
3979
|
loadWorkbook,
|
|
3936
3980
|
mergeMap,
|
|
3937
3981
|
parseWorkSheetRules,
|