tfose5-xlsx 1.0.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.
Files changed (51) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +1 -0
  3. package/dist/cell-parser-base.d.ts +9 -0
  4. package/dist/cell-parser-base.js +20 -0
  5. package/dist/cell-parser-parse-option.d.ts +16 -0
  6. package/dist/cell-parser-parse-option.js +2 -0
  7. package/dist/cell-to-array-parser.d.ts +8 -0
  8. package/dist/cell-to-array-parser.js +22 -0
  9. package/dist/cell-to-bool-parser.d.ts +5 -0
  10. package/dist/cell-to-bool-parser.js +13 -0
  11. package/dist/cell-to-enum-parser.d.ts +5 -0
  12. package/dist/cell-to-enum-parser.js +16 -0
  13. package/dist/cell-to-json-parser.d.ts +5 -0
  14. package/dist/cell-to-json-parser.js +20 -0
  15. package/dist/cell-to-number-parser.d.ts +5 -0
  16. package/dist/cell-to-number-parser.js +9 -0
  17. package/dist/cell-to-rewards-parser.d.ts +11 -0
  18. package/dist/cell-to-rewards-parser.js +38 -0
  19. package/dist/cell-to-string-parser.d.ts +5 -0
  20. package/dist/cell-to-string-parser.js +9 -0
  21. package/dist/cell-to-unix-parser.d.ts +5 -0
  22. package/dist/cell-to-unix-parser.js +18 -0
  23. package/dist/cell-to-value-conditions-parser.d.ts +11 -0
  24. package/dist/cell-to-value-conditions-parser.js +38 -0
  25. package/dist/cell-to-value-parser.d.ts +10 -0
  26. package/dist/cell-to-value-parser.js +25 -0
  27. package/dist/enum-item.d.ts +6 -0
  28. package/dist/enum-item.js +2 -0
  29. package/dist/enum-sheet-parser-base.d.ts +6 -0
  30. package/dist/enum-sheet-parser-base.js +6 -0
  31. package/dist/enum-sheet-parser-parse-option.d.ts +7 -0
  32. package/dist/enum-sheet-parser-parse-option.js +2 -0
  33. package/dist/enum-sheet-parser.d.ts +12 -0
  34. package/dist/enum-sheet-parser.js +142 -0
  35. package/dist/file-parser-base.d.ts +5 -0
  36. package/dist/file-parser-base.js +6 -0
  37. package/dist/file-parser-parse-result.d.ts +7 -0
  38. package/dist/file-parser-parse-result.js +2 -0
  39. package/dist/file-parser.d.ts +10 -0
  40. package/dist/file-parser.js +22 -0
  41. package/dist/i-parser.d.ts +3 -0
  42. package/dist/i-parser.js +2 -0
  43. package/dist/index.d.ts +4 -0
  44. package/dist/index.js +20 -0
  45. package/dist/mock.d.ts +12 -0
  46. package/dist/mock.js +59 -0
  47. package/dist/parser-factory.d.ts +7 -0
  48. package/dist/parser-factory.js +15 -0
  49. package/dist/value.d.ts +4 -0
  50. package/dist/value.js +2 -0
  51. package/package.json +29 -0
@@ -0,0 +1,9 @@
1
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
2
+ import { EnumItem } from './enum-item';
3
+ import { IXlsxParser } from './i-parser';
4
+ export declare abstract class XlsxCellParserBase<T> implements IXlsxParser<XlsxCellParserParseOption, T> {
5
+ abstract parse(opt: XlsxCellParserParseOption): T;
6
+ protected getEnumFieldIndexDoc(enumName: string, opt: XlsxCellParserParseOption, field?: keyof EnumItem): {
7
+ [fieldValue: string]: number;
8
+ };
9
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellParserBase = void 0;
4
+ class XlsxCellParserBase {
5
+ getEnumFieldIndexDoc(enumName, opt, field = 'text') {
6
+ var _a, _b, _c;
7
+ var _d;
8
+ (_a = opt.allEnumIndexDoc) !== null && _a !== void 0 ? _a : (opt.allEnumIndexDoc = {});
9
+ const allIndexDoc = (_b = (_d = opt.allEnumIndexDoc)[enumName]) !== null && _b !== void 0 ? _b : (_d[enumName] = {});
10
+ if (!allIndexDoc[field]) {
11
+ allIndexDoc[field] = {};
12
+ const allItem = (_c = opt.allEnumItem[enumName]) !== null && _c !== void 0 ? _c : new Map();
13
+ allItem.forEach(r => {
14
+ allIndexDoc[field][r[field]] = r.value;
15
+ });
16
+ }
17
+ return allIndexDoc[field];
18
+ }
19
+ }
20
+ exports.XlsxCellParserBase = XlsxCellParserBase;
@@ -0,0 +1,16 @@
1
+ import { EnumItem } from './enum-item';
2
+ export type XlsxCellParserParseOption = {
3
+ ext: string;
4
+ field: string;
5
+ value: any;
6
+ allEnumItem: {
7
+ [enumName: string]: Map<number, EnumItem>;
8
+ };
9
+ allEnumIndexDoc?: {
10
+ [enumName: string]: {
11
+ [field: string]: {
12
+ [fieldValue: string]: number;
13
+ };
14
+ };
15
+ };
16
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
2
+ import { XlsxEnumSheetParser } from './enum-sheet-parser';
3
+ import { IXlsxParser } from './i-parser';
4
+ export declare class XlsxCellToArrayParser implements IXlsxParser<XlsxCellParserParseOption, unknown[]> {
5
+ private m_EnumSheetParser;
6
+ constructor(m_EnumSheetParser: XlsxEnumSheetParser);
7
+ parse(opt: XlsxCellParserParseOption): unknown[];
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellToArrayParser = void 0;
4
+ class XlsxCellToArrayParser {
5
+ constructor(m_EnumSheetParser) {
6
+ this.m_EnumSheetParser = m_EnumSheetParser;
7
+ }
8
+ parse(opt) {
9
+ var _a;
10
+ if (typeof opt.value != 'string')
11
+ return [];
12
+ const [type, ...others] = opt.ext.split('.');
13
+ const lines = opt.value.split(((_a = others[0]) === null || _a === void 0 ? void 0 : _a.startsWith('\\')) ? new RegExp(others.shift(), 'g') : /\r\n|\n|\r/g);
14
+ const res = [];
15
+ const otherExt = others.join('.');
16
+ for (const r of lines) {
17
+ res.push(this.m_EnumSheetParser.getCellParser(type).parse(Object.assign(Object.assign({}, opt), { ext: otherExt, value: r })));
18
+ }
19
+ return res;
20
+ }
21
+ }
22
+ exports.XlsxCellToArrayParser = XlsxCellToArrayParser;
@@ -0,0 +1,5 @@
1
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
2
+ import { IXlsxParser } from './i-parser';
3
+ export declare class XlsxCellToBoolParser implements IXlsxParser<XlsxCellParserParseOption, boolean> {
4
+ parse(opt: XlsxCellParserParseOption): boolean;
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellToBoolParser = void 0;
4
+ class XlsxCellToBoolParser {
5
+ parse(opt) {
6
+ if (typeof opt.value == 'boolean')
7
+ return opt.value;
8
+ if (typeof opt.value == 'string')
9
+ return opt.value.toLocaleLowerCase() == 'true';
10
+ return !!opt.value;
11
+ }
12
+ }
13
+ exports.XlsxCellToBoolParser = XlsxCellToBoolParser;
@@ -0,0 +1,5 @@
1
+ import { XlsxCellParserBase } from './cell-parser-base';
2
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
3
+ export declare class XlsxCellToEnumParser extends XlsxCellParserBase<number> {
4
+ parse(opt: XlsxCellParserParseOption): number;
5
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellToEnumParser = void 0;
4
+ const tfose5_error_1 = require("tfose5-error");
5
+ const cell_parser_base_1 = require("./cell-parser-base");
6
+ class XlsxCellToEnumParser extends cell_parser_base_1.XlsxCellParserBase {
7
+ parse(opt) {
8
+ const [_, enumName, field] = opt.ext.split('.');
9
+ const indexDoc = this.getEnumFieldIndexDoc(enumName, opt, field);
10
+ const no = indexDoc[opt.value];
11
+ if (!no)
12
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${XlsxCellToEnumParser.name}.parse: 无效${enumName}[${opt.value}]`);
13
+ return no;
14
+ }
15
+ }
16
+ exports.XlsxCellToEnumParser = XlsxCellToEnumParser;
@@ -0,0 +1,5 @@
1
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
2
+ import { IXlsxParser } from './i-parser';
3
+ export declare class XlsxCellToJsonParser implements IXlsxParser<XlsxCellParserParseOption, unknown> {
4
+ parse(opt: XlsxCellParserParseOption): Promise<any>;
5
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.XlsxCellToJsonParser = void 0;
13
+ class XlsxCellToJsonParser {
14
+ parse(opt) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ return typeof opt.value == 'string' ? JSON.parse(opt.value) : opt.value;
17
+ });
18
+ }
19
+ }
20
+ exports.XlsxCellToJsonParser = XlsxCellToJsonParser;
@@ -0,0 +1,5 @@
1
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
2
+ import { IXlsxParser } from './i-parser';
3
+ export declare class XlsxCellToNumberParser implements IXlsxParser<XlsxCellParserParseOption, number> {
4
+ parse(opt: XlsxCellParserParseOption): number;
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellToNumberParser = void 0;
4
+ class XlsxCellToNumberParser {
5
+ parse(opt) {
6
+ return Number(opt.value);
7
+ }
8
+ }
9
+ exports.XlsxCellToNumberParser = XlsxCellToNumberParser;
@@ -0,0 +1,11 @@
1
+ import { XlsxCellParserBase } from './cell-parser-base';
2
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
3
+ import { Value } from './value';
4
+ type Reward = Value & {
5
+ weight?: number;
6
+ };
7
+ export declare class XlsxCellToRewardsParser extends XlsxCellParserBase<Reward[][]> {
8
+ static reg: RegExp;
9
+ parse(opt: XlsxCellParserParseOption): Reward[][];
10
+ }
11
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellToRewardsParser = void 0;
4
+ const tfose5_error_1 = require("tfose5-error");
5
+ const cell_parser_base_1 = require("./cell-parser-base");
6
+ class XlsxCellToRewardsParser extends cell_parser_base_1.XlsxCellParserBase {
7
+ parse(opt) {
8
+ if (typeof opt.value != 'string')
9
+ return [];
10
+ const lines = opt.value.split(/\r\n|\n|\r/g);
11
+ const res = [[]];
12
+ const valueTypeTextOfValue = this.getEnumFieldIndexDoc('ValueTypeData', opt);
13
+ for (const r of lines) {
14
+ const match = r.match(XlsxCellToRewardsParser.reg);
15
+ if (!match) {
16
+ if (res[res.length - 1].length) {
17
+ res.push([]);
18
+ continue;
19
+ }
20
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效奖励格式[${r}]`);
21
+ }
22
+ const valueType = valueTypeTextOfValue[match[1]];
23
+ if (!valueType)
24
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效奖励名[${r}]`);
25
+ const count = Number(match[2]);
26
+ if (isNaN(count))
27
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效奖励数量[${r}]`);
28
+ res[res.length - 1].push({
29
+ count,
30
+ valueType,
31
+ weight: match[3] && Number(match[3].slice(1)) || 0,
32
+ });
33
+ }
34
+ return res;
35
+ }
36
+ }
37
+ exports.XlsxCellToRewardsParser = XlsxCellToRewardsParser;
38
+ XlsxCellToRewardsParser.reg = /^([^*]+)\*(-?[\deE+\.]+)(\*?(\d+))?$/;
@@ -0,0 +1,5 @@
1
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
2
+ import { IXlsxParser } from './i-parser';
3
+ export declare class XlsxCellToStringParser implements IXlsxParser<XlsxCellParserParseOption, string> {
4
+ parse(opt: XlsxCellParserParseOption): any;
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellToStringParser = void 0;
4
+ class XlsxCellToStringParser {
5
+ parse(opt) {
6
+ return (typeof opt.value == 'string' ? opt.value : opt.value.toString()).trim();
7
+ }
8
+ }
9
+ exports.XlsxCellToStringParser = XlsxCellToStringParser;
@@ -0,0 +1,5 @@
1
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
2
+ import { IXlsxParser } from './i-parser';
3
+ export declare class XlsxCellToUnixParser implements IXlsxParser<XlsxCellParserParseOption, number> {
4
+ parse(opt: XlsxCellParserParseOption): number;
5
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.XlsxCellToUnixParser = void 0;
7
+ const dayjs_1 = __importDefault(require("dayjs"));
8
+ class XlsxCellToUnixParser {
9
+ parse(opt) {
10
+ try {
11
+ return (0, dayjs_1.default)(opt.value.toString()).unix();
12
+ }
13
+ catch (_a) {
14
+ return 0;
15
+ }
16
+ }
17
+ }
18
+ exports.XlsxCellToUnixParser = XlsxCellToUnixParser;
@@ -0,0 +1,11 @@
1
+ import { XlsxCellParserBase } from './cell-parser-base';
2
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
3
+ import { Value } from './value';
4
+ type ValueCondition = Value & {
5
+ op: string;
6
+ };
7
+ export declare class XlsxCellToValueConditionsParser extends XlsxCellParserBase<ValueCondition[][]> {
8
+ static reg: RegExp;
9
+ parse(opt: XlsxCellParserParseOption): ValueCondition[][];
10
+ }
11
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellToValueConditionsParser = void 0;
4
+ const tfose5_error_1 = require("tfose5-error");
5
+ const cell_parser_base_1 = require("./cell-parser-base");
6
+ class XlsxCellToValueConditionsParser extends cell_parser_base_1.XlsxCellParserBase {
7
+ parse(opt) {
8
+ if (typeof opt.value != 'string')
9
+ return [];
10
+ const lines = opt.value.split(/\r\n|\n|\r/g);
11
+ let res = [[]];
12
+ const valueTypeTextOfValue = this.getEnumFieldIndexDoc('ValueTypeData', opt);
13
+ for (const r of lines) {
14
+ const match = r.match(XlsxCellToValueConditionsParser.reg);
15
+ if (!match) {
16
+ if (res[res.length - 1].length) {
17
+ res.push([]);
18
+ continue;
19
+ }
20
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效数值条件格式[${r}]`);
21
+ }
22
+ const valueType = valueTypeTextOfValue[match[1]];
23
+ if (!valueType)
24
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效数值条件名[${r}]`);
25
+ const count = Number(match[4]);
26
+ if (isNaN(count))
27
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效数值条件数量[${r}]`);
28
+ res[res.length - 1].push({
29
+ count,
30
+ op: match[2] && match[2] + match[3] || match[3],
31
+ valueType,
32
+ });
33
+ }
34
+ return res;
35
+ }
36
+ }
37
+ exports.XlsxCellToValueConditionsParser = XlsxCellToValueConditionsParser;
38
+ XlsxCellToValueConditionsParser.reg = /^([\u4e00-\u9fff]+)(%|&|now-day|now-diff|own)*([=><]+)(-?\d+([\.eE+\d]+)?)$/;
@@ -0,0 +1,10 @@
1
+ import { XlsxCellParserBase } from './cell-parser-base';
2
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
3
+ import { Value } from './value';
4
+ export declare class XlsxCellToValueParser extends XlsxCellParserBase<Value> {
5
+ static reg: RegExp;
6
+ parse(opt: XlsxCellParserParseOption): {
7
+ count: number;
8
+ valueType: number;
9
+ };
10
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxCellToValueParser = void 0;
4
+ const tfose5_error_1 = require("tfose5-error");
5
+ const cell_parser_base_1 = require("./cell-parser-base");
6
+ class XlsxCellToValueParser extends cell_parser_base_1.XlsxCellParserBase {
7
+ parse(opt) {
8
+ const match = opt.value.toString().match(XlsxCellToValueParser.reg);
9
+ if (!match)
10
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效数值格式[${opt.value}]`);
11
+ const valueTypeTextOfValue = this.getEnumFieldIndexDoc('ValueTypeData', opt);
12
+ const valueType = valueTypeTextOfValue[match[1]];
13
+ if (!valueType)
14
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效数值名[${opt.value}]`);
15
+ const count = Number(match[2]);
16
+ if (isNaN(count))
17
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.parse: 无效数值数量[${opt.value}]`);
18
+ return {
19
+ count,
20
+ valueType,
21
+ };
22
+ }
23
+ }
24
+ exports.XlsxCellToValueParser = XlsxCellToValueParser;
25
+ XlsxCellToValueParser.reg = /^(.+)\*(-?[\.eE+\d]+)$/;
@@ -0,0 +1,6 @@
1
+ export type EnumItem = {
2
+ value: number;
3
+ } & Partial<{
4
+ key: string;
5
+ text: string;
6
+ }>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { EnumItem } from './enum-item';
2
+ import { XlsxEnumSheetParserParseOption } from './enum-sheet-parser-parse-option';
3
+ import { IXlsxParser } from './i-parser';
4
+ export declare abstract class XlsxEnumSheetParserBase implements IXlsxParser<XlsxEnumSheetParserParseOption, EnumItem[]> {
5
+ abstract parse(input: XlsxEnumSheetParserParseOption): EnumItem[];
6
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxEnumSheetParserBase = void 0;
4
+ class XlsxEnumSheetParserBase {
5
+ }
6
+ exports.XlsxEnumSheetParserBase = XlsxEnumSheetParserBase;
@@ -0,0 +1,7 @@
1
+ import { EnumItem } from './enum-item';
2
+ import { XlsxFileParserParseResult } from './file-parser-parse-result';
3
+ export type XlsxEnumSheetParserParseOption = XlsxFileParserParseResult & {
4
+ allEnumItem: {
5
+ [enumName: string]: Map<number, EnumItem>;
6
+ };
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { XlsxCellParserParseOption } from './cell-parser-parse-option';
2
+ import { XlsxEnumSheetParserBase } from './enum-sheet-parser-base';
3
+ import { XlsxEnumSheetParserParseOption } from './enum-sheet-parser-parse-option';
4
+ import { IXlsxParser } from './i-parser';
5
+ export declare class XlsxEnumSheetParser extends XlsxEnumSheetParserBase {
6
+ private m_AllCellParser?;
7
+ protected get allCellParser(): {
8
+ [type: string]: IXlsxParser<XlsxCellParserParseOption, unknown>;
9
+ };
10
+ getCellParser(type: string): IXlsxParser<XlsxCellParserParseOption, unknown>;
11
+ parse(opt: XlsxEnumSheetParserParseOption): any;
12
+ }
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxEnumSheetParser = void 0;
4
+ const tfose5_error_1 = require("tfose5-error");
5
+ const cell_to_array_parser_1 = require("./cell-to-array-parser");
6
+ const cell_to_bool_parser_1 = require("./cell-to-bool-parser");
7
+ const cell_to_enum_parser_1 = require("./cell-to-enum-parser");
8
+ const cell_to_json_parser_1 = require("./cell-to-json-parser");
9
+ const cell_to_number_parser_1 = require("./cell-to-number-parser");
10
+ const cell_to_rewards_parser_1 = require("./cell-to-rewards-parser");
11
+ const cell_to_string_parser_1 = require("./cell-to-string-parser");
12
+ const cell_to_unix_parser_1 = require("./cell-to-unix-parser");
13
+ const cell_to_value_parser_1 = require("./cell-to-value-parser");
14
+ const cell_to_value_conditions_parser_1 = require("./cell-to-value-conditions-parser");
15
+ const enum_sheet_parser_base_1 = require("./enum-sheet-parser-base");
16
+ const numReg = /^\d+$/;
17
+ class XlsxEnumSheetParser extends enum_sheet_parser_base_1.XlsxEnumSheetParserBase {
18
+ get allCellParser() {
19
+ var _a;
20
+ (_a = this.m_AllCellParser) !== null && _a !== void 0 ? _a : (this.m_AllCellParser = {
21
+ array: new cell_to_array_parser_1.XlsxCellToArrayParser(this),
22
+ bool: new cell_to_bool_parser_1.XlsxCellToBoolParser(),
23
+ enum: new cell_to_enum_parser_1.XlsxCellToEnumParser(),
24
+ json: new cell_to_json_parser_1.XlsxCellToJsonParser(),
25
+ number: new cell_to_number_parser_1.XlsxCellToNumberParser(),
26
+ rewards: new cell_to_rewards_parser_1.XlsxCellToRewardsParser(),
27
+ string: new cell_to_string_parser_1.XlsxCellToStringParser(),
28
+ unix: new cell_to_unix_parser_1.XlsxCellToUnixParser(),
29
+ value: new cell_to_value_parser_1.XlsxCellToValueParser(),
30
+ valueConditions: new cell_to_value_conditions_parser_1.XlsxCellToValueConditionsParser(),
31
+ });
32
+ return this.m_AllCellParser;
33
+ }
34
+ getCellParser(type) {
35
+ const parser = this.allCellParser[type];
36
+ if (!parser)
37
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, `${this.constructor.name}.getCellParser: 无效解析器[${type}]`);
38
+ return parser;
39
+ }
40
+ parse(opt) {
41
+ var _a, _b, _c, _d;
42
+ const allTable = {};
43
+ for (const r of opt.sheets) {
44
+ const rows = [];
45
+ const tempRows = [];
46
+ for (let i = 1; i < r.rows.length; i++) {
47
+ let row = {};
48
+ let tempRow = {};
49
+ const sheetRow = r.rows[i];
50
+ let isFirstField = true;
51
+ for (const k in sheetRow) {
52
+ const [field, type, ext] = k.split(':');
53
+ if (!type)
54
+ continue;
55
+ let fieldValue;
56
+ if (type == '#') {
57
+ let [associateTable, associateField] = ext.split('.');
58
+ fieldValue = allTable[associateTable];
59
+ if (!fieldValue)
60
+ continue;
61
+ associateField !== null && associateField !== void 0 ? associateField : (associateField = associateTable);
62
+ let cellValue = sheetRow[k];
63
+ for (const ck in sheetRow) {
64
+ if (ck.split(':')[0] == associateField) {
65
+ cellValue = sheetRow[ck];
66
+ break;
67
+ }
68
+ }
69
+ if (cellValue != undefined) {
70
+ fieldValue = fieldValue.filter(cr => {
71
+ return cr[associateField] == cellValue;
72
+ }).map(cr => {
73
+ cr = structuredClone(cr);
74
+ delete cr.value;
75
+ delete cr[associateField];
76
+ return cr;
77
+ });
78
+ }
79
+ }
80
+ else {
81
+ const parser = this.allCellParser[type];
82
+ if (!parser)
83
+ continue;
84
+ try {
85
+ fieldValue = parser.parse({
86
+ allEnumItem: opt.allEnumItem,
87
+ ext,
88
+ field,
89
+ value: sheetRow[k],
90
+ });
91
+ }
92
+ catch (ex) {
93
+ throw new tfose5_error_1.CustomError(tfose5_error_1.ErrorCode.warning, JSON.stringify({
94
+ field: k,
95
+ row: i + 2,
96
+ sheet: r.name,
97
+ text: ex.data,
98
+ }));
99
+ }
100
+ }
101
+ if (isFirstField) {
102
+ const rowIndex = rows.findIndex(cr => cr[field] == fieldValue);
103
+ if (rowIndex == -1) {
104
+ rows.push(row);
105
+ tempRows.push(tempRow);
106
+ }
107
+ else {
108
+ row = rows[rowIndex];
109
+ tempRow = tempRows[rowIndex];
110
+ }
111
+ isFirstField = false;
112
+ }
113
+ const fieldParts = field.split('.');
114
+ if (fieldParts.length > 1) {
115
+ let obj = row;
116
+ while (fieldParts.length) {
117
+ let name = fieldParts.shift();
118
+ if (name in tempRow && typeof tempRow[name] != 'object')
119
+ name = tempRow[name];
120
+ if (fieldParts.length) {
121
+ (_a = obj[name]) !== null && _a !== void 0 ? _a : (obj[name] = numReg.test(fieldParts[0]) ? [] : {});
122
+ obj = obj[name];
123
+ }
124
+ else if ((_b = name.startsWith) === null || _b === void 0 ? void 0 : _b.call(name, '[')) {
125
+ tempRow[name.substring(1, name.length - 1)] = fieldValue;
126
+ }
127
+ else {
128
+ obj[name] = fieldValue;
129
+ }
130
+ }
131
+ }
132
+ else if (!field.startsWith('_')) {
133
+ (_c = row[field]) !== null && _c !== void 0 ? _c : (row[field] = fieldValue);
134
+ }
135
+ }
136
+ }
137
+ allTable[r.name] = rows;
138
+ }
139
+ return (_d = allTable[opt.enumName]) !== null && _d !== void 0 ? _d : [];
140
+ }
141
+ }
142
+ exports.XlsxEnumSheetParser = XlsxEnumSheetParser;
@@ -0,0 +1,5 @@
1
+ import { XlsxFileParserParseResult } from './file-parser-parse-result';
2
+ import { IXlsxParser } from './i-parser';
3
+ export declare abstract class XlsxFileParserBase implements IXlsxParser<string, XlsxFileParserParseResult> {
4
+ abstract parse(path: string): XlsxFileParserParseResult;
5
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxFileParserBase = void 0;
4
+ class XlsxFileParserBase {
5
+ }
6
+ exports.XlsxFileParserBase = XlsxFileParserBase;
@@ -0,0 +1,7 @@
1
+ export type XlsxFileParserParseResult = {
2
+ enumName: string;
3
+ sheets: {
4
+ name: string;
5
+ rows: object[];
6
+ }[];
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { XlsxFileParserBase } from './file-parser-base';
2
+ export declare class XlsxFileParser extends XlsxFileParserBase {
3
+ parse(path: string): {
4
+ sheets: {
5
+ name: string;
6
+ rows: object[];
7
+ }[];
8
+ enumName: string;
9
+ };
10
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XlsxFileParser = void 0;
4
+ const xlsx_1 = require("xlsx");
5
+ const file_parser_base_1 = require("./file-parser-base");
6
+ class XlsxFileParser extends file_parser_base_1.XlsxFileParserBase {
7
+ parse(path) {
8
+ const wb = (0, xlsx_1.readFile)(path);
9
+ return {
10
+ sheets: wb.SheetNames.filter(r => {
11
+ return !r.includes('_');
12
+ }).map(r => {
13
+ return {
14
+ name: r,
15
+ rows: xlsx_1.utils.sheet_to_json(wb.Sheets[r]),
16
+ };
17
+ }).reverse(),
18
+ enumName: wb.SheetNames[0],
19
+ };
20
+ }
21
+ }
22
+ exports.XlsxFileParser = XlsxFileParser;
@@ -0,0 +1,3 @@
1
+ export interface IXlsxParser<TIn, TOut> {
2
+ parse(input: TIn): TOut;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export * from './enum-sheet-parser-base';
2
+ export * from './file-parser-base';
3
+ export * from './i-parser';
4
+ export * from './parser-factory';