@senlinz/import-export 0.1.1 → 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.
- package/README.md +11 -24
- package/README.zh.md +11 -24
- package/dist/assets/imexport_wasm_bg-lSJMSNpC.wasm +0 -0
- package/dist/index.js +1 -1
- package/dist/types/ExcelDefinition.d.ts +7 -1
- package/dist/types/index.d.ts +2 -14
- package/dist/types/utils.d.ts +22 -2
- package/package.json +6 -5
- package/dist/types/runtime.d.ts +0 -20
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
type ExcelColumnDataType = "text" | "number" | "date" | "image";
|
|
5
5
|
/**
|
|
6
6
|
* Runtime support:
|
|
7
|
-
* - Browser ESM environments with `Blob`, `FileReader`, `
|
|
7
|
+
* - Browser ESM environments with `Blob`, `FileReader`, `fetch`, and `URL.createObjectURL`.
|
|
8
8
|
* - Node.js can use `fromExcel`, `toExcel`, and `generateExcelTemplate` when compatible browser globals are available.
|
|
9
9
|
*
|
|
10
10
|
* Known limitations:
|
|
@@ -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. */
|
|
@@ -104,6 +108,8 @@ interface DynamicExcelImportOptions {
|
|
|
104
108
|
sheetName?: string;
|
|
105
109
|
/** 1-based worksheet row number to use as the header row. Defaults to the first non-empty row. */
|
|
106
110
|
headerRow?: number;
|
|
111
|
+
/** Maximum upload size (in bytes) enforced for browser-based dynamic imports. Defaults to 25 MiB when omitted. */
|
|
112
|
+
maxFileSizeBytes?: number;
|
|
107
113
|
}
|
|
108
114
|
interface DynamicExcelImportResult {
|
|
109
115
|
/** Actual worksheet name that was imported. */
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
export type * from './ExcelDefinition';
|
|
2
|
-
export type { InitializeWasmOptions } from './runtime.js';
|
|
3
2
|
import { ExcelDefinition } from './ExcelDefinition';
|
|
4
3
|
import type { DynamicExcelImportOptions, DynamicExcelImportResult } from './ExcelDefinition';
|
|
5
|
-
import {
|
|
6
|
-
import { bundledWasmSource, initializeWasm } from './runtime.js';
|
|
7
|
-
declare function getUtils(): {
|
|
8
|
-
importExcel: typeof importExcel;
|
|
9
|
-
importExcelDynamic: typeof importExcelDynamic;
|
|
10
|
-
exportExcel: typeof exportExcel;
|
|
11
|
-
downloadExcelTemplate: typeof downloadExcelTemplate;
|
|
12
|
-
fromExcel: typeof fromExcel;
|
|
13
|
-
fromExcelDynamic: typeof fromExcelDynamic;
|
|
14
|
-
toExcel: typeof toExcel;
|
|
15
|
-
generateExcelTemplate: typeof generateExcelTemplate;
|
|
16
|
-
};
|
|
4
|
+
import { testUtils } from './utils.js';
|
|
17
5
|
declare function _importExcel<T>(definition: ExcelDefinition): Promise<T[]>;
|
|
18
6
|
declare function _importExcelDynamic(options?: DynamicExcelImportOptions): Promise<DynamicExcelImportResult>;
|
|
19
7
|
declare function _exportExcel<T>(definition: ExcelDefinition, data: T[]): Promise<void>;
|
|
@@ -22,4 +10,4 @@ declare function _fromExcelDynamic(buffer: Uint8Array, options?: DynamicExcelImp
|
|
|
22
10
|
declare function _toExcel<T>(definition: ExcelDefinition, data: T[]): Promise<Uint8Array>;
|
|
23
11
|
declare function _downloadExcelTemplate(definition: ExcelDefinition): Promise<void>;
|
|
24
12
|
declare function _generateExcelTemplate(definition: ExcelDefinition): Promise<Uint8Array>;
|
|
25
|
-
export {
|
|
13
|
+
export { _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,4 +1,24 @@
|
|
|
1
|
-
import { ExcelDefinition, DynamicExcelImportOptions, DynamicExcelImportResult } 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[]>;
|
|
3
23
|
declare function _fromExcelDynamic(buffer: Uint8Array, options?: DynamicExcelImportOptions): Promise<DynamicExcelImportResult>;
|
|
4
24
|
declare function _toExcel<T>(definition: ExcelDefinition, data: T[]): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -8,4 +28,4 @@ declare function download(data: Uint8Array | string, name: string, type?: string
|
|
|
8
28
|
declare function importExcel<T>(definition: ExcelDefinition): Promise<T[]>;
|
|
9
29
|
declare function importExcelDynamic(options?: DynamicExcelImportOptions): Promise<DynamicExcelImportResult>;
|
|
10
30
|
declare function exportExcel<T>(definition: ExcelDefinition, data: T[]): Promise<void>;
|
|
11
|
-
export { importExcel, importExcelDynamic, exportExcel, downloadExcelTemplate, _fromExcel as fromExcel, _fromExcelDynamic as fromExcelDynamic, _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,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senlinz/import-export",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "import/export excel core",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*.js",
|
|
7
7
|
"dist/**/*.d.ts",
|
|
8
|
+
"dist/**/*.wasm",
|
|
8
9
|
"README.md",
|
|
9
10
|
"README.zh.md"
|
|
10
11
|
],
|
|
@@ -24,10 +25,10 @@
|
|
|
24
25
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
25
26
|
"@types/jest": "^29.5.6",
|
|
26
27
|
"@types/node": "^16.18.108",
|
|
28
|
+
"fflate": "^0.8.2",
|
|
27
29
|
"jest": "^29.7.0",
|
|
28
30
|
"jest-cli": "^29.7.0",
|
|
29
|
-
"rollup": "^4.
|
|
30
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
31
|
+
"rollup": "^4.60.2",
|
|
31
32
|
"tslib": "^2.8.1",
|
|
32
33
|
"typescript": "^5.8.2"
|
|
33
34
|
},
|
|
@@ -38,8 +39,7 @@
|
|
|
38
39
|
"url": "git+https://github.com/gui-xie/import-export.git"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
-
"@senlinz/import-export-wasm": "0.1.1"
|
|
42
|
+
"@senlinz/import-export-wasm": "1.0.0"
|
|
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
|
}
|
package/dist/types/runtime.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
type WasmInitializationInputKind = 'source' | 'bytes' | 'module';
|
|
2
|
-
interface InitializeWasmOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Gzipped base64-encoded WASM source text.
|
|
5
|
-
*/
|
|
6
|
-
source?: string;
|
|
7
|
-
/**
|
|
8
|
-
* Raw WebAssembly bytes loaded by the caller.
|
|
9
|
-
*/
|
|
10
|
-
bytes?: BufferSource;
|
|
11
|
-
/**
|
|
12
|
-
* A precompiled WebAssembly module loaded by the caller.
|
|
13
|
-
*/
|
|
14
|
-
module?: WebAssembly.Module;
|
|
15
|
-
}
|
|
16
|
-
declare const bundledWasmSource: string;
|
|
17
|
-
declare function ensureWasmInitialized(): void;
|
|
18
|
-
declare function initializeWasm(options?: InitializeWasmOptions): void;
|
|
19
|
-
export { bundledWasmSource, ensureWasmInitialized, initializeWasm, };
|
|
20
|
-
export type { InitializeWasmOptions, WasmInitializationInputKind, };
|