@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.d.mts
CHANGED
|
@@ -402,6 +402,7 @@ type CompileResult = {
|
|
|
402
402
|
configure?: RuleResult;
|
|
403
403
|
errs?: Error[];
|
|
404
404
|
};
|
|
405
|
+
declare const loadCompileSheets: (workbook: exceljs.Workbook, ruleSheetName: string | number) => string[];
|
|
405
406
|
declare const compileWorkSheet: <T extends ArrayBuffer | Buffer | string>(data: T, sheetName: string | number, options?: RuleOptions) => Promise<exceljs.Xlsx | Error[]>;
|
|
406
407
|
declare class ExprResolver {
|
|
407
408
|
static toBuffer: (w: exceljs.Workbook) => Promise<Buffer>;
|
|
@@ -469,4 +470,4 @@ declare const mergeMap: (source: Map<string, string>, dest: Map<string, string>)
|
|
|
469
470
|
declare const autoRegisterAlias: (values: Object, configure: RuleResult) => Object;
|
|
470
471
|
declare const generateCommandsXlsxTemplateWithCompile: <T extends JsZip.OutputType>(data: Buffer, values: Object, compileOptions: AutoOptions, options?: JsZip.JSZipGeneratorOptions<T> & FullOptions) => Promise<OutputByType[T]>;
|
|
471
472
|
|
|
472
|
-
export { AddCommand, AddCommandMust, type AfterReplaceHook, type Argument, ArgumentData, ArgumentValue, ArgumentValueLoader, type AutoOptions, type BeforeReplaceHook, BufferType, type CellPosition, type CmdFunction, CompileContext, type CompileResult, type CustomFormatter, type CustomPlaceholderExtractor, type CustomReplacer, DefaultPlaceholderCellValue, type DrawingInfo, ExprResolver, type ExtensionOptions, type ExtractMacroArgs, type FilterMacroResult, type FullOptions, type MacroArgs, type MacroUnitHelper, type OutputByType, type Placeholder, type PlaceholderCellValue, type QueryFunction, type Range, type Ref, type RelsInfo, RuleMapOptions, type RuleOptions, type RuleResult, RuleToken, type SheetInfo, type TableInfo, TokenParserManger, Workbook, type WorkbookOptions, autoRegisterAlias, columnLetterToNumber, columnNumberToLetter, commandExtendQuery, compileRuleSheetName, compileWorkSheet, compileWorkSheetPlaceholder, defaultExtractPlaceholders, defaultFormatters, defaultValueDotGet, generateCommandsXlsxTemplate, generateCommandsXlsxTemplateWithCompile, generateXlsxTemplate, getCommands, getTokenParser, hasGeneratorToken, isRuleToken, isUrl, loadWorkbook, mergeMap, parseWorkSheetRules, registerTokenParser, registerTokenParserMust, resolveArgument, scanCellSetPlaceholder, toArrayBuffer, valueDotGet, workSheetSetPlaceholder };
|
|
473
|
+
export { AddCommand, AddCommandMust, type AfterReplaceHook, type Argument, ArgumentData, ArgumentValue, ArgumentValueLoader, type AutoOptions, type BeforeReplaceHook, BufferType, type CellPosition, type CmdFunction, CompileContext, type CompileResult, type CustomFormatter, type CustomPlaceholderExtractor, type CustomReplacer, DefaultPlaceholderCellValue, type DrawingInfo, ExprResolver, type ExtensionOptions, type ExtractMacroArgs, type FilterMacroResult, type FullOptions, type MacroArgs, type MacroUnitHelper, type OutputByType, type Placeholder, type PlaceholderCellValue, type QueryFunction, type Range, type Ref, type RelsInfo, RuleMapOptions, type RuleOptions, type RuleResult, RuleToken, type SheetInfo, type TableInfo, TokenParserManger, Workbook, type WorkbookOptions, autoRegisterAlias, columnLetterToNumber, columnNumberToLetter, commandExtendQuery, compileRuleSheetName, compileWorkSheet, compileWorkSheetPlaceholder, defaultExtractPlaceholders, defaultFormatters, defaultValueDotGet, generateCommandsXlsxTemplate, generateCommandsXlsxTemplateWithCompile, generateXlsxTemplate, getCommands, getTokenParser, hasGeneratorToken, isRuleToken, isUrl, loadCompileSheets, loadWorkbook, mergeMap, parseWorkSheetRules, registerTokenParser, registerTokenParserMust, resolveArgument, scanCellSetPlaceholder, toArrayBuffer, valueDotGet, workSheetSetPlaceholder };
|
package/dist/index.d.ts
CHANGED
|
@@ -402,6 +402,7 @@ type CompileResult = {
|
|
|
402
402
|
configure?: RuleResult;
|
|
403
403
|
errs?: Error[];
|
|
404
404
|
};
|
|
405
|
+
declare const loadCompileSheets: (workbook: exceljs.Workbook, ruleSheetName: string | number) => string[];
|
|
405
406
|
declare const compileWorkSheet: <T extends ArrayBuffer | Buffer | string>(data: T, sheetName: string | number, options?: RuleOptions) => Promise<exceljs.Xlsx | Error[]>;
|
|
406
407
|
declare class ExprResolver {
|
|
407
408
|
static toBuffer: (w: exceljs.Workbook) => Promise<Buffer>;
|
|
@@ -469,4 +470,4 @@ declare const mergeMap: (source: Map<string, string>, dest: Map<string, string>)
|
|
|
469
470
|
declare const autoRegisterAlias: (values: Object, configure: RuleResult) => Object;
|
|
470
471
|
declare const generateCommandsXlsxTemplateWithCompile: <T extends JsZip.OutputType>(data: Buffer, values: Object, compileOptions: AutoOptions, options?: JsZip.JSZipGeneratorOptions<T> & FullOptions) => Promise<OutputByType[T]>;
|
|
471
472
|
|
|
472
|
-
export { AddCommand, AddCommandMust, type AfterReplaceHook, type Argument, ArgumentData, ArgumentValue, ArgumentValueLoader, type AutoOptions, type BeforeReplaceHook, BufferType, type CellPosition, type CmdFunction, CompileContext, type CompileResult, type CustomFormatter, type CustomPlaceholderExtractor, type CustomReplacer, DefaultPlaceholderCellValue, type DrawingInfo, ExprResolver, type ExtensionOptions, type ExtractMacroArgs, type FilterMacroResult, type FullOptions, type MacroArgs, type MacroUnitHelper, type OutputByType, type Placeholder, type PlaceholderCellValue, type QueryFunction, type Range, type Ref, type RelsInfo, RuleMapOptions, type RuleOptions, type RuleResult, RuleToken, type SheetInfo, type TableInfo, TokenParserManger, Workbook, type WorkbookOptions, autoRegisterAlias, columnLetterToNumber, columnNumberToLetter, commandExtendQuery, compileRuleSheetName, compileWorkSheet, compileWorkSheetPlaceholder, defaultExtractPlaceholders, defaultFormatters, defaultValueDotGet, generateCommandsXlsxTemplate, generateCommandsXlsxTemplateWithCompile, generateXlsxTemplate, getCommands, getTokenParser, hasGeneratorToken, isRuleToken, isUrl, loadWorkbook, mergeMap, parseWorkSheetRules, registerTokenParser, registerTokenParserMust, resolveArgument, scanCellSetPlaceholder, toArrayBuffer, valueDotGet, workSheetSetPlaceholder };
|
|
473
|
+
export { AddCommand, AddCommandMust, type AfterReplaceHook, type Argument, ArgumentData, ArgumentValue, ArgumentValueLoader, type AutoOptions, type BeforeReplaceHook, BufferType, type CellPosition, type CmdFunction, CompileContext, type CompileResult, type CustomFormatter, type CustomPlaceholderExtractor, type CustomReplacer, DefaultPlaceholderCellValue, type DrawingInfo, ExprResolver, type ExtensionOptions, type ExtractMacroArgs, type FilterMacroResult, type FullOptions, type MacroArgs, type MacroUnitHelper, type OutputByType, type Placeholder, type PlaceholderCellValue, type QueryFunction, type Range, type Ref, type RelsInfo, RuleMapOptions, type RuleOptions, type RuleResult, RuleToken, type SheetInfo, type TableInfo, TokenParserManger, Workbook, type WorkbookOptions, autoRegisterAlias, columnLetterToNumber, columnNumberToLetter, commandExtendQuery, compileRuleSheetName, compileWorkSheet, compileWorkSheetPlaceholder, defaultExtractPlaceholders, defaultFormatters, defaultValueDotGet, generateCommandsXlsxTemplate, generateCommandsXlsxTemplateWithCompile, generateXlsxTemplate, getCommands, getTokenParser, hasGeneratorToken, isRuleToken, isUrl, loadCompileSheets, loadWorkbook, mergeMap, parseWorkSheetRules, registerTokenParser, registerTokenParserMust, resolveArgument, scanCellSetPlaceholder, toArrayBuffer, valueDotGet, workSheetSetPlaceholder };
|
package/dist/index.js
CHANGED
|
@@ -62,6 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
hasGeneratorToken: () => hasGeneratorToken,
|
|
63
63
|
isRuleToken: () => isRuleToken,
|
|
64
64
|
isUrl: () => isUrl,
|
|
65
|
+
loadCompileSheets: () => loadCompileSheets,
|
|
65
66
|
loadWorkbook: () => loadWorkbook,
|
|
66
67
|
mergeMap: () => mergeMap,
|
|
67
68
|
parseWorkSheetRules: () => parseWorkSheetRules,
|
|
@@ -2075,6 +2076,7 @@ var exprIndex = `index`;
|
|
|
2075
2076
|
var defaultKey = `!!`;
|
|
2076
2077
|
var numberKey = `!!number`;
|
|
2077
2078
|
var codeKey = `!!codeKey`;
|
|
2079
|
+
var codeAliasKey = `!!codeAliasKey`;
|
|
2078
2080
|
var funcCommand = "fn:";
|
|
2079
2081
|
var RuleToken = /* @__PURE__ */ ((RuleToken2) => {
|
|
2080
2082
|
RuleToken2["AliasToken"] = "alias";
|
|
@@ -2130,16 +2132,16 @@ var RuleMapOptions = class _RuleMapOptions {
|
|
|
2130
2132
|
}
|
|
2131
2133
|
parseDefault(worksheet) {
|
|
2132
2134
|
this.ruleKeyMap = mergeOption(this.ruleKeyMap, defaultRuleTokenMap);
|
|
2133
|
-
if (this.startLine === void 0) {
|
|
2135
|
+
if (this.startLine === void 0 || isNaN(this.startLine) || this.startLine < 0) {
|
|
2134
2136
|
this.startLine = 1;
|
|
2135
2137
|
}
|
|
2136
|
-
if (this.endLine === void 0) {
|
|
2138
|
+
if (this.endLine === void 0 || isNaN(this.endLine) || this.endLine < 0) {
|
|
2137
2139
|
this.endLine = worksheet.rowCount;
|
|
2138
2140
|
}
|
|
2139
|
-
if (this.startColumn === void 0) {
|
|
2141
|
+
if (this.startColumn === void 0 || isNaN(this.startColumn) || this.startColumn < 0) {
|
|
2140
2142
|
this.startColumn = 1;
|
|
2141
2143
|
}
|
|
2142
|
-
if (this.endColumn === void 0) {
|
|
2144
|
+
if (this.endColumn === void 0 || isNaN(this.endColumn) || this.endColumn < 0) {
|
|
2143
2145
|
this.endColumn = worksheet.columnCount;
|
|
2144
2146
|
}
|
|
2145
2147
|
return this;
|
|
@@ -3047,7 +3049,7 @@ var resolveCompileMacroGen = (ctx, expr, currentCellIndex) => {
|
|
|
3047
3049
|
var getExprEnd = function(macroExpr, matchIndex, rparenToken) {
|
|
3048
3050
|
return macroExpr.indexOf(rparenToken, matchIndex);
|
|
3049
3051
|
};
|
|
3050
|
-
var macroFormatters = [numberKey, codeKey];
|
|
3052
|
+
var macroFormatters = [numberKey, codeKey, codeAliasKey];
|
|
3051
3053
|
var extractMacro = function(expr, options) {
|
|
3052
3054
|
let end = NaN;
|
|
3053
3055
|
const offset = options.startToken.length;
|
|
@@ -3086,9 +3088,17 @@ var __codeKey = (str) => {
|
|
|
3086
3088
|
var __numberKey = (str) => {
|
|
3087
3089
|
return Number.parseInt(str, 10).toString();
|
|
3088
3090
|
};
|
|
3091
|
+
var __codeAliasKey = (str) => {
|
|
3092
|
+
const key = __codeKey(str);
|
|
3093
|
+
if (key !== "") {
|
|
3094
|
+
return `${defaultRuleTokenParserMap.get("@" /* UseAliasToken */)}${key}`;
|
|
3095
|
+
}
|
|
3096
|
+
return "";
|
|
3097
|
+
};
|
|
3089
3098
|
var macroFormatter = /* @__PURE__ */ new Map([
|
|
3090
3099
|
[codeKey, __codeKey],
|
|
3091
3100
|
[numberKey, __numberKey],
|
|
3101
|
+
[codeAliasKey, __codeAliasKey],
|
|
3092
3102
|
[defaultKey, (v) => v]
|
|
3093
3103
|
]);
|
|
3094
3104
|
var execMacroFormat = function(value, formatter) {
|
|
@@ -3569,6 +3579,25 @@ var compileWorkSheetPlaceholder = function(ctx, sheet, result) {
|
|
|
3569
3579
|
}
|
|
3570
3580
|
return void 0;
|
|
3571
3581
|
};
|
|
3582
|
+
var loadCompileSheets = (workbook, ruleSheetName) => {
|
|
3583
|
+
let first;
|
|
3584
|
+
let sheets = [];
|
|
3585
|
+
for (const [_, w] of workbook.worksheets.entries()) {
|
|
3586
|
+
if (w.name === ruleSheetName) {
|
|
3587
|
+
continue;
|
|
3588
|
+
}
|
|
3589
|
+
if (first === "") {
|
|
3590
|
+
first = w.name;
|
|
3591
|
+
}
|
|
3592
|
+
if (!w.name.endsWith(".json") && !w.name.endsWith(".config")) {
|
|
3593
|
+
sheets.push(w.name);
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
if (sheets.length <= 0 && first !== "") {
|
|
3597
|
+
sheets.push(first);
|
|
3598
|
+
}
|
|
3599
|
+
return sheets;
|
|
3600
|
+
};
|
|
3572
3601
|
var compile = async function(data, ruleSheetName, options) {
|
|
3573
3602
|
const workbook = await loadWorkbook(data);
|
|
3574
3603
|
const sheet = workbook.getWorksheet(ruleSheetName);
|
|
@@ -3587,6 +3616,10 @@ var compile = async function(data, ruleSheetName, options) {
|
|
|
3587
3616
|
const excludes = [ruleSheetName];
|
|
3588
3617
|
options = RuleMapOptions.withAllSheets(workbook, excludes);
|
|
3589
3618
|
}
|
|
3619
|
+
options = options.parseDefault(sheet);
|
|
3620
|
+
if (options.compileSheets === void 0 || options.compileSheets.length === 0) {
|
|
3621
|
+
options.compileSheets = loadCompileSheets(workbook, ruleSheetName);
|
|
3622
|
+
}
|
|
3590
3623
|
const result = parseWorkSheetRules(sheet, options);
|
|
3591
3624
|
const errs = compileCheck(result, options);
|
|
3592
3625
|
if (errs !== void 0) {
|
|
@@ -3649,6 +3682,9 @@ var fetchAlias = (m) => {
|
|
|
3649
3682
|
};
|
|
3650
3683
|
var removeUnExportSheets = (w, options) => {
|
|
3651
3684
|
const removes = [];
|
|
3685
|
+
if (typeof options.skipRemoveUnExportSheet === "boolean" && options.skipRemoveUnExportSheet === true) {
|
|
3686
|
+
return w;
|
|
3687
|
+
}
|
|
3652
3688
|
if (options.compileSheets === void 0 || options.compileSheets.length <= 0) {
|
|
3653
3689
|
for (const [i, v] of w.worksheets.entries()) {
|
|
3654
3690
|
const sheetName = v.name;
|
|
@@ -3691,6 +3727,7 @@ ExprResolver.resolveCompileMacroGen = resolveCompileMacroGen;
|
|
|
3691
3727
|
ExprResolver.resolveCompileMacroExpr = resolveCompileMacroExpr;
|
|
3692
3728
|
|
|
3693
3729
|
// src/extends.ts
|
|
3730
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
3694
3731
|
function hasToString(obj) {
|
|
3695
3732
|
return obj != null && typeof obj.toString === "function";
|
|
3696
3733
|
}
|
|
@@ -3960,6 +3997,12 @@ var autoRegisterAlias = function(values, configure) {
|
|
|
3960
3997
|
values[aliasKey] = alias;
|
|
3961
3998
|
return values;
|
|
3962
3999
|
};
|
|
4000
|
+
var saveCompile = async (compileOptions, wb) => {
|
|
4001
|
+
if (typeof compileOptions.save === "boolean" && compileOptions.save === true && typeof compileOptions.saveFile === "string" && compileOptions.saveFile !== "") {
|
|
4002
|
+
const path2 = compileOptions.saveFile;
|
|
4003
|
+
await import_promises.default.writeFile(`${path2}compile_${(/* @__PURE__ */ new Date()).valueOf()}.xlsx`, wb);
|
|
4004
|
+
}
|
|
4005
|
+
};
|
|
3963
4006
|
var generateCommandsXlsxTemplateWithCompile = async function(data, values, compileOptions, options) {
|
|
3964
4007
|
if (compileOptions.sheetName === void 0 || compileOptions.sheetName === "") {
|
|
3965
4008
|
compileOptions.sheetName = compileRuleSheetName;
|
|
@@ -3971,6 +4014,7 @@ var generateCommandsXlsxTemplateWithCompile = async function(data, values, compi
|
|
|
3971
4014
|
values = autoRegisterAlias(values, result.configure);
|
|
3972
4015
|
result.workbook = ExprResolver.removeUnExportSheets(result.workbook, compileOptions);
|
|
3973
4016
|
const wb = await ExprResolver.toBuffer(result.workbook);
|
|
4017
|
+
await saveCompile(compileOptions, wb);
|
|
3974
4018
|
const w = await Workbook.parse(wb, options);
|
|
3975
4019
|
w.setQueryFunctionHandler(commandExtendQuery);
|
|
3976
4020
|
await w.substituteAll(values);
|
|
@@ -4010,6 +4054,7 @@ var generateCommandsXlsxTemplateWithCompile = async function(data, values, compi
|
|
|
4010
4054
|
hasGeneratorToken,
|
|
4011
4055
|
isRuleToken,
|
|
4012
4056
|
isUrl,
|
|
4057
|
+
loadCompileSheets,
|
|
4013
4058
|
loadWorkbook,
|
|
4014
4059
|
mergeMap,
|
|
4015
4060
|
parseWorkSheetRules,
|