Skip to content

Commit bb44bad

Browse files
committed
Fix TypeScript exported types.
1 parent 6811cfe commit bb44bad

7 files changed

+67
-31
lines changed

README.md

+22-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
# Revision history:
2323

24+
### 3.9.3
25+
26+
* Fix TypeScript exported types
27+
2428
### 3.9.0
2529

2630
* Cell types and formats!!! Now you can define the cell type and format. For example, you can define a cell as a date or a number. You can also define the format of the cell. For example, you can define a cell as a date with the format "dd/mm/yyyy" or a number with the format "#,##0.00".
@@ -278,15 +282,28 @@ Each element in the format array consists on:
278282
}
279283
```
280284

281-
`format` can be used from one of the predefined types if you use TypeScript
285+
Example:
282286

283287
```typescript
284-
{
285-
"range": "A1:A100",
286-
"format": PredefinedFormat.INTEGER
287-
}
288+
formats: [
289+
{
290+
range: "C2:C20",
291+
format: {
292+
type: "n",
293+
pattern: "0.00",
294+
},
295+
},
296+
{
297+
range: "C2:C20",
298+
format: ExcellentExport.formats.NUMBER,
299+
}
300+
],
301+
288302
```
289303

304+
`format` can be used from one of the predefined types if you use TypeScript
305+
306+
290307
`cell_type` can be one of the followint:
291308

292309
's': String

dist/excellentexport.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @url: https://github.com/jmaister/excellentexport
77
*
88
*/
9-
import { FormatDefinition } from './format';
9+
import { CellTypes, FormatDefinition, CellFormats, CellPatterns } from './format';
1010
declare global {
1111
interface Navigator {
1212
msSaveBlob?: (blob: any, defaultName?: string) => boolean;
@@ -35,9 +35,11 @@ export interface SheetOptions {
3535
}
3636
declare const ExcellentExport: {
3737
version: () => string;
38-
formats: import("./format").CellFormats;
3938
excel: (anchor: (HTMLAnchorElement | string), table: HTMLTableElement, name: string) => boolean;
4039
csv: (anchor: (HTMLAnchorElement | string), table: HTMLTableElement, delimiter?: string, newLine?: string) => boolean;
4140
convert: (options: ConvertOptions, sheets: SheetOptions[]) => string | false;
41+
formats: CellFormats;
42+
cellTypes: typeof CellTypes;
43+
cellPatterns: typeof CellPatterns;
4244
};
4345
export default ExcellentExport;

dist/excellentexport.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/format.d.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export declare enum CellType {
1+
export declare enum CellTypes {
22
TEXT = "s",
33
NUMBER = "n",
44
DATE = "d",
55
BOOLEAN = "b"
66
}
7-
export declare enum CellPattern {
7+
export declare enum CellPatterns {
88
INTEGER = "0",
99
DECIMAL = "0.00",
1010
DATE = "dd/mm/yyyy",
@@ -15,9 +15,10 @@ export declare enum CellPattern {
1515
EXPONENT = "0.00E+00",
1616
TEXT = "@"
1717
}
18+
export type CellType = 's' | 'n' | 'd' | 'b';
1819
export interface CellFormat {
1920
type: CellType;
20-
pattern?: CellPattern;
21+
pattern?: string;
2122
}
2223
export interface CellFormats {
2324
[key: string]: CellFormat;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "excellentexport",
3-
"version": "3.9.0",
3+
"version": "3.9.3",
44
"description": "Client side JavaScript export to Excel or CSV",
55
"license": "MIT",
66
"homepage": "http://jordiburgos.com",

src/excellentexport.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import * as XLSX from 'xlsx';
11-
import { CellType, FormatDefinition, PredefinedFormat } from './format';
11+
import { CellTypes, FormatDefinition, PredefinedFormat, CellFormats, CellPatterns } from './format';
1212

1313
import * as utils from './utils';
1414

@@ -42,9 +42,19 @@ export interface SheetOptions {
4242
formats?: (FormatDefinition | null)[],
4343
}
4444

45+
/*
46+
export type ExcellentExportType = {
47+
version: () => string,
48+
formats: CellFormats,
49+
excel: (anchor:(HTMLAnchorElement|string), table:HTMLTableElement, name:string) => void,
50+
csv: (anchor:(HTMLAnchorElement|string), table:HTMLTableElement, delimiter?:string, newLine?:string) => void,
51+
convert: (options:ConvertOptions, sheets:SheetOptions[]) => void,
52+
}
53+
*/
54+
4555
const ExcellentExport = function() {
4656

47-
const version = "3.9.0";
57+
const version = "3.9.3";
4858

4959
/*
5060
ExcellentExport.convert(options, sheets);
@@ -153,7 +163,7 @@ const ExcellentExport = function() {
153163
cell.t = f.format.type;
154164

155165
// type fix
156-
if (f.format?.type == CellType.BOOLEAN) {
166+
if (f.format?.type == CellTypes.BOOLEAN) {
157167
const v = cell.v.toString().toLowerCase();
158168
if (v == 'true' || v == '1') cell.v = true;
159169
if (v == 'false' || v == '0') cell.v = false;
@@ -208,7 +218,6 @@ const ExcellentExport = function() {
208218
version: function(): string {
209219
return version;
210220
},
211-
formats: PredefinedFormat,
212221
excel: function(anchor:(HTMLAnchorElement|string), table:HTMLTableElement, name:string) {
213222
table = utils.getTable(table);
214223
anchor = utils.getAnchor(anchor);
@@ -235,7 +244,10 @@ const ExcellentExport = function() {
235244
},
236245
convert: function(options:ConvertOptions, sheets:SheetOptions[]) {
237246
return convert(options, sheets);
238-
}
247+
},
248+
formats: PredefinedFormat,
249+
cellTypes: CellTypes,
250+
cellPatterns: CellPatterns,
239251
};
240252
}();
241253

src/format.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

2-
export enum CellType {
2+
// Constants for cell types
3+
export enum CellTypes {
34
TEXT = 's',
45
NUMBER = 'n',
56
DATE = 'd',
67
BOOLEAN = 'b',
78
}
89

9-
export enum CellPattern {
10+
// Constants for cell patterns
11+
export enum CellPatterns {
1012
INTEGER = '0',
1113
DECIMAL = '0.00',
1214
DATE = 'dd/mm/yyyy',
@@ -18,31 +20,33 @@ export enum CellPattern {
1820
TEXT = '@',
1921
}
2022

23+
export type CellType = 's' | 'n' | 'd' | 'b';
24+
2125
export interface CellFormat {
2226
type: CellType,
23-
pattern?: CellPattern,
27+
pattern?: string,
2428
}
2529

2630
// Define structure for predefined formats
2731
export interface CellFormats {
2832
[key: string]: CellFormat
2933
}
3034
export const PredefinedFormat : CellFormats = {
31-
NUMBER: { type: CellType.NUMBER},
32-
INTEGER: { type: CellType.NUMBER, pattern: CellPattern.INTEGER },
33-
DECIMAL: { type: CellType.NUMBER, pattern: CellPattern.DECIMAL },
34-
CURRENCY: { type: CellType.NUMBER, pattern: CellPattern.CURRENCY },
35-
PERCENTAGE: { type: CellType.NUMBER, pattern: CellPattern.PERCENTAGE },
36-
EXPONENT: { type: CellType.NUMBER, pattern: CellPattern.EXPONENT },
35+
NUMBER: { type: CellTypes.NUMBER},
36+
INTEGER: { type: CellTypes.NUMBER, pattern: CellPatterns.INTEGER },
37+
DECIMAL: { type: CellTypes.NUMBER, pattern: CellPatterns.DECIMAL },
38+
CURRENCY: { type: CellTypes.NUMBER, pattern: CellPatterns.CURRENCY },
39+
PERCENTAGE: { type: CellTypes.NUMBER, pattern: CellPatterns.PERCENTAGE },
40+
EXPONENT: { type: CellTypes.NUMBER, pattern: CellPatterns.EXPONENT },
3741

38-
DATE: { type: CellType.DATE, pattern: CellPattern.DATE },
42+
DATE: { type: CellTypes.DATE, pattern: CellPatterns.DATE },
3943

40-
TIME: { type: CellType.DATE, pattern: CellPattern.TIME },
41-
DATETIME: { type: CellType.DATE, pattern: CellPattern.DATETIME },
44+
TIME: { type: CellTypes.DATE, pattern: CellPatterns.TIME },
45+
DATETIME: { type: CellTypes.DATE, pattern: CellPatterns.DATETIME },
4246

43-
TEXT: { type: CellType.TEXT, pattern: CellPattern.TEXT },
47+
TEXT: { type: CellTypes.TEXT, pattern: CellPatterns.TEXT },
4448

45-
BOOLEAN: { type: CellType.BOOLEAN },
49+
BOOLEAN: { type: CellTypes.BOOLEAN },
4650
}
4751

4852
export interface FormatDefinition {

0 commit comments

Comments
 (0)