@senlinz/import-export 0.1.0 → 0.1.2
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 +45 -2
- package/README.zh.md +38 -3
- package/dist/index.js +1 -1
- package/dist/types/ExcelDefinition.d.ts +22 -2
- package/dist/types/index.d.ts +7 -2
- package/dist/types/utils.d.ts +24 -2
- package/package.json +3 -2
|
@@ -8,7 +8,7 @@ type ExcelColumnDataType = "text" | "number" | "date" | "image";
|
|
|
8
8
|
* - Node.js can use `fromExcel`, `toExcel`, and `generateExcelTemplate` when compatible browser globals are available.
|
|
9
9
|
*
|
|
10
10
|
* Known limitations:
|
|
11
|
-
* -
|
|
11
|
+
* - Schema-based import validates headers strictly against `columns[].name` order and position.
|
|
12
12
|
* - Grouped export expects parent columns and data groups to be declared before children.
|
|
13
13
|
* - Image export requires `imageFetcher`.
|
|
14
14
|
*/
|
|
@@ -29,6 +29,8 @@ interface ExcelDefinition {
|
|
|
29
29
|
titleHeight?: number;
|
|
30
30
|
/** Format applied to the optional merged title row. */
|
|
31
31
|
titleFormat?: ExcelCellFormatDefinition;
|
|
32
|
+
/** Maximum upload size (in bytes) enforced for browser-based imports. Defaults to 25 MiB when omitted. */
|
|
33
|
+
maxFileSizeBytes?: number;
|
|
32
34
|
/** Default height used for data rows when exporting a worksheet. */
|
|
33
35
|
defaultRowHeight?: number;
|
|
34
36
|
/** Height applied to header rows during template/export generation. */
|
|
@@ -46,6 +48,8 @@ interface ExcelDefinition {
|
|
|
46
48
|
* The callback must resolve to image bytes for the provided URL or identifier.
|
|
47
49
|
*/
|
|
48
50
|
imageFetcher?: (url: string) => Promise<Uint8Array>;
|
|
51
|
+
/** Escapes text cells that look like formulas to prevent Excel formula injection. Enabled by default. */
|
|
52
|
+
escapeFormulas?: boolean;
|
|
49
53
|
}
|
|
50
54
|
interface ExcelColumnDefinition {
|
|
51
55
|
/** Stable programmatic key used to map row objects. Must be unique within a definition. */
|
|
@@ -99,4 +103,20 @@ interface ExcelCellFormatDefinition {
|
|
|
99
103
|
dateFormat?: string;
|
|
100
104
|
borderColor?: string;
|
|
101
105
|
}
|
|
102
|
-
|
|
106
|
+
interface DynamicExcelImportOptions {
|
|
107
|
+
/** Preferred worksheet name. Falls back to the first sheet when omitted or missing. */
|
|
108
|
+
sheetName?: string;
|
|
109
|
+
/** 1-based worksheet row number to use as the header row. Defaults to the first non-empty row. */
|
|
110
|
+
headerRow?: number;
|
|
111
|
+
/** Maximum upload size (in bytes) enforced for browser-based dynamic imports. Defaults to 25 MiB when omitted. */
|
|
112
|
+
maxFileSizeBytes?: number;
|
|
113
|
+
}
|
|
114
|
+
interface DynamicExcelImportResult {
|
|
115
|
+
/** Actual worksheet name that was imported. */
|
|
116
|
+
sheetName: string;
|
|
117
|
+
/** Header labels read from the worksheet in left-to-right order. */
|
|
118
|
+
headers: string[];
|
|
119
|
+
/** Row data keyed by the imported header labels. */
|
|
120
|
+
rows: Record<string, string>[];
|
|
121
|
+
}
|
|
122
|
+
export { ExcelDefinition, ExcelColumnDefinition, ExcelCellFormatDefinition, ExcelColumnDataType, DynamicExcelImportOptions, DynamicExcelImportResult };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
export type * from './ExcelDefinition';
|
|
2
2
|
export type { InitializeWasmOptions } from './runtime.js';
|
|
3
3
|
import { ExcelDefinition } from './ExcelDefinition';
|
|
4
|
-
import {
|
|
4
|
+
import type { DynamicExcelImportOptions, DynamicExcelImportResult } from './ExcelDefinition';
|
|
5
|
+
import { importExcel, importExcelDynamic, exportExcel, downloadExcelTemplate, fromExcel, fromExcelDynamic, toExcel, generateExcelTemplate, testUtils } from './utils.js';
|
|
5
6
|
import { bundledWasmSource, initializeWasm } from './runtime.js';
|
|
6
7
|
declare function getUtils(): {
|
|
7
8
|
importExcel: typeof importExcel;
|
|
9
|
+
importExcelDynamic: typeof importExcelDynamic;
|
|
8
10
|
exportExcel: typeof exportExcel;
|
|
9
11
|
downloadExcelTemplate: typeof downloadExcelTemplate;
|
|
10
12
|
fromExcel: typeof fromExcel;
|
|
13
|
+
fromExcelDynamic: typeof fromExcelDynamic;
|
|
11
14
|
toExcel: typeof toExcel;
|
|
12
15
|
generateExcelTemplate: typeof generateExcelTemplate;
|
|
13
16
|
};
|
|
14
17
|
declare function _importExcel<T>(definition: ExcelDefinition): Promise<T[]>;
|
|
18
|
+
declare function _importExcelDynamic(options?: DynamicExcelImportOptions): Promise<DynamicExcelImportResult>;
|
|
15
19
|
declare function _exportExcel<T>(definition: ExcelDefinition, data: T[]): Promise<void>;
|
|
16
20
|
declare function _fromExcel<T>(definition: ExcelDefinition, buffer: Uint8Array): Promise<T[]>;
|
|
21
|
+
declare function _fromExcelDynamic(buffer: Uint8Array, options?: DynamicExcelImportOptions): Promise<DynamicExcelImportResult>;
|
|
17
22
|
declare function _toExcel<T>(definition: ExcelDefinition, data: T[]): Promise<Uint8Array>;
|
|
18
23
|
declare function _downloadExcelTemplate(definition: ExcelDefinition): Promise<void>;
|
|
19
24
|
declare function _generateExcelTemplate(definition: ExcelDefinition): Promise<Uint8Array>;
|
|
20
|
-
export { bundledWasmSource, getUtils, initializeWasm, _importExcel as importExcel, _exportExcel as exportExcel, _fromExcel as fromExcel, _toExcel as toExcel, _downloadExcelTemplate as downloadExcelTemplate, _generateExcelTemplate as generateExcelTemplate, };
|
|
25
|
+
export { bundledWasmSource, getUtils, initializeWasm, _importExcel as importExcel, _importExcelDynamic as importExcelDynamic, _exportExcel as exportExcel, _fromExcel as fromExcel, _fromExcelDynamic as fromExcelDynamic, _toExcel as toExcel, _downloadExcelTemplate as downloadExcelTemplate, _generateExcelTemplate as generateExcelTemplate, testUtils, };
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
|
-
import { ExcelDefinition } from './ExcelDefinition';
|
|
1
|
+
import { ExcelColumnDefinition, ExcelDefinition, DynamicExcelImportOptions, DynamicExcelImportResult } from './ExcelDefinition';
|
|
2
|
+
declare const SUPPORTED_DATA_TYPES: readonly ["text", "number", "date", "image"];
|
|
3
|
+
type NormalizedDataType = typeof SUPPORTED_DATA_TYPES[number];
|
|
4
|
+
type NormalizedExcelColumnDefinition = Omit<ExcelColumnDefinition, 'dataType'> & {
|
|
5
|
+
dataType?: NormalizedDataType;
|
|
6
|
+
};
|
|
7
|
+
type NormalizedExcelDefinition = Omit<ExcelDefinition, 'columns'> & {
|
|
8
|
+
columns: NormalizedExcelColumnDefinition[];
|
|
9
|
+
maxFileSizeBytes: number;
|
|
10
|
+
escapeFormulas: boolean;
|
|
11
|
+
};
|
|
12
|
+
type NormalizedDynamicImportOptions = DynamicExcelImportOptions & {
|
|
13
|
+
maxFileSizeBytes: number;
|
|
14
|
+
};
|
|
15
|
+
type TestingUtils = {
|
|
16
|
+
normalizeDefinition(definition: ExcelDefinition): NormalizedExcelDefinition;
|
|
17
|
+
normalizeDynamicImportOptions(options?: DynamicExcelImportOptions): NormalizedDynamicImportOptions;
|
|
18
|
+
sanitizeTextCellValue(value: string, escapeFormulas?: boolean): string;
|
|
19
|
+
defaultMaxFileSizeBytes: number;
|
|
20
|
+
};
|
|
21
|
+
declare const testUtils: TestingUtils;
|
|
2
22
|
declare function _fromExcel<T>(definition: ExcelDefinition, buffer: Uint8Array): Promise<T[]>;
|
|
23
|
+
declare function _fromExcelDynamic(buffer: Uint8Array, options?: DynamicExcelImportOptions): Promise<DynamicExcelImportResult>;
|
|
3
24
|
declare function _toExcel<T>(definition: ExcelDefinition, data: T[]): Promise<Uint8Array<ArrayBufferLike>>;
|
|
4
25
|
declare function generateExcelTemplate(definition: ExcelDefinition): Promise<Uint8Array<ArrayBufferLike>>;
|
|
5
26
|
declare function downloadExcelTemplate(definition: ExcelDefinition): Promise<void>;
|
|
6
27
|
declare function download(data: Uint8Array | string, name: string, type?: string): void;
|
|
7
28
|
declare function importExcel<T>(definition: ExcelDefinition): Promise<T[]>;
|
|
29
|
+
declare function importExcelDynamic(options?: DynamicExcelImportOptions): Promise<DynamicExcelImportResult>;
|
|
8
30
|
declare function exportExcel<T>(definition: ExcelDefinition, data: T[]): Promise<void>;
|
|
9
|
-
export { importExcel, exportExcel, downloadExcelTemplate, _fromExcel as fromExcel, _toExcel as toExcel, generateExcelTemplate, download };
|
|
31
|
+
export { importExcel, importExcelDynamic, exportExcel, downloadExcelTemplate, _fromExcel as fromExcel, _fromExcelDynamic as fromExcelDynamic, _toExcel as toExcel, generateExcelTemplate, download, testUtils };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senlinz/import-export",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "import/export excel core",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"fflate": "^0.8.2",
|
|
42
|
-
"@senlinz/import-export-wasm": "0.1.
|
|
42
|
+
"@senlinz/import-export-wasm": "0.1.2"
|
|
43
43
|
},
|
|
44
44
|
"keywords": [
|
|
45
45
|
"rust",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "rollup -c",
|
|
59
59
|
"dev": "rollup -c -w",
|
|
60
|
+
"test:unit": "npm run build && node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config jest.config.mjs --runInBand",
|
|
60
61
|
"test": "playwright test -c playwright.config.ts",
|
|
61
62
|
"e2e-serve": "serve -l 8080 ."
|
|
62
63
|
}
|