Skip to content

Commit

Permalink
Fix TypeScript exported types.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaister committed Mar 4, 2023
1 parent 6811cfe commit bb44bad
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 31 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

# Revision history:

### 3.9.3

* Fix TypeScript exported types

### 3.9.0

* 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".
Expand Down Expand Up @@ -278,15 +282,28 @@ Each element in the format array consists on:
}
```

`format` can be used from one of the predefined types if you use TypeScript
Example:

```typescript
{
"range": "A1:A100",
"format": PredefinedFormat.INTEGER
}
formats: [
{
range: "C2:C20",
format: {
type: "n",
pattern: "0.00",
},
},
{
range: "C2:C20",
format: ExcellentExport.formats.NUMBER,
}
],

```

`format` can be used from one of the predefined types if you use TypeScript


`cell_type` can be one of the followint:

's': String
Expand Down
6 changes: 4 additions & 2 deletions dist/excellentexport.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @url: https://github.com/jmaister/excellentexport
*
*/
import { FormatDefinition } from './format';
import { CellTypes, FormatDefinition, CellFormats, CellPatterns } from './format';
declare global {
interface Navigator {
msSaveBlob?: (blob: any, defaultName?: string) => boolean;
Expand Down Expand Up @@ -35,9 +35,11 @@ export interface SheetOptions {
}
declare const ExcellentExport: {
version: () => string;
formats: import("./format").CellFormats;
excel: (anchor: (HTMLAnchorElement | string), table: HTMLTableElement, name: string) => boolean;
csv: (anchor: (HTMLAnchorElement | string), table: HTMLTableElement, delimiter?: string, newLine?: string) => boolean;
convert: (options: ConvertOptions, sheets: SheetOptions[]) => string | false;
formats: CellFormats;
cellTypes: typeof CellTypes;
cellPatterns: typeof CellPatterns;
};
export default ExcellentExport;
2 changes: 1 addition & 1 deletion dist/excellentexport.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions dist/format.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export declare enum CellType {
export declare enum CellTypes {
TEXT = "s",
NUMBER = "n",
DATE = "d",
BOOLEAN = "b"
}
export declare enum CellPattern {
export declare enum CellPatterns {
INTEGER = "0",
DECIMAL = "0.00",
DATE = "dd/mm/yyyy",
Expand All @@ -15,9 +15,10 @@ export declare enum CellPattern {
EXPONENT = "0.00E+00",
TEXT = "@"
}
export type CellType = 's' | 'n' | 'd' | 'b';
export interface CellFormat {
type: CellType;
pattern?: CellPattern;
pattern?: string;
}
export interface CellFormats {
[key: string]: CellFormat;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "excellentexport",
"version": "3.9.0",
"version": "3.9.3",
"description": "Client side JavaScript export to Excel or CSV",
"license": "MIT",
"homepage": "http://jordiburgos.com",
Expand Down
22 changes: 17 additions & 5 deletions src/excellentexport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

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

import * as utils from './utils';

Expand Down Expand Up @@ -42,9 +42,19 @@ export interface SheetOptions {
formats?: (FormatDefinition | null)[],
}

/*
export type ExcellentExportType = {
version: () => string,
formats: CellFormats,
excel: (anchor:(HTMLAnchorElement|string), table:HTMLTableElement, name:string) => void,
csv: (anchor:(HTMLAnchorElement|string), table:HTMLTableElement, delimiter?:string, newLine?:string) => void,
convert: (options:ConvertOptions, sheets:SheetOptions[]) => void,
}
*/

const ExcellentExport = function() {

const version = "3.9.0";
const version = "3.9.3";

/*
ExcellentExport.convert(options, sheets);
Expand Down Expand Up @@ -153,7 +163,7 @@ const ExcellentExport = function() {
cell.t = f.format.type;

// type fix
if (f.format?.type == CellType.BOOLEAN) {
if (f.format?.type == CellTypes.BOOLEAN) {
const v = cell.v.toString().toLowerCase();
if (v == 'true' || v == '1') cell.v = true;
if (v == 'false' || v == '0') cell.v = false;
Expand Down Expand Up @@ -208,7 +218,6 @@ const ExcellentExport = function() {
version: function(): string {
return version;
},
formats: PredefinedFormat,
excel: function(anchor:(HTMLAnchorElement|string), table:HTMLTableElement, name:string) {
table = utils.getTable(table);
anchor = utils.getAnchor(anchor);
Expand All @@ -235,7 +244,10 @@ const ExcellentExport = function() {
},
convert: function(options:ConvertOptions, sheets:SheetOptions[]) {
return convert(options, sheets);
}
},
formats: PredefinedFormat,
cellTypes: CellTypes,
cellPatterns: CellPatterns,
};
}();

Expand Down
32 changes: 18 additions & 14 deletions src/format.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

export enum CellType {
// Constants for cell types
export enum CellTypes {
TEXT = 's',
NUMBER = 'n',
DATE = 'd',
BOOLEAN = 'b',
}

export enum CellPattern {
// Constants for cell patterns
export enum CellPatterns {
INTEGER = '0',
DECIMAL = '0.00',
DATE = 'dd/mm/yyyy',
Expand All @@ -18,31 +20,33 @@ export enum CellPattern {
TEXT = '@',
}

export type CellType = 's' | 'n' | 'd' | 'b';

export interface CellFormat {
type: CellType,
pattern?: CellPattern,
pattern?: string,
}

// Define structure for predefined formats
export interface CellFormats {
[key: string]: CellFormat
}
export const PredefinedFormat : CellFormats = {
NUMBER: { type: CellType.NUMBER},
INTEGER: { type: CellType.NUMBER, pattern: CellPattern.INTEGER },
DECIMAL: { type: CellType.NUMBER, pattern: CellPattern.DECIMAL },
CURRENCY: { type: CellType.NUMBER, pattern: CellPattern.CURRENCY },
PERCENTAGE: { type: CellType.NUMBER, pattern: CellPattern.PERCENTAGE },
EXPONENT: { type: CellType.NUMBER, pattern: CellPattern.EXPONENT },
NUMBER: { type: CellTypes.NUMBER},
INTEGER: { type: CellTypes.NUMBER, pattern: CellPatterns.INTEGER },
DECIMAL: { type: CellTypes.NUMBER, pattern: CellPatterns.DECIMAL },
CURRENCY: { type: CellTypes.NUMBER, pattern: CellPatterns.CURRENCY },
PERCENTAGE: { type: CellTypes.NUMBER, pattern: CellPatterns.PERCENTAGE },
EXPONENT: { type: CellTypes.NUMBER, pattern: CellPatterns.EXPONENT },

DATE: { type: CellType.DATE, pattern: CellPattern.DATE },
DATE: { type: CellTypes.DATE, pattern: CellPatterns.DATE },

TIME: { type: CellType.DATE, pattern: CellPattern.TIME },
DATETIME: { type: CellType.DATE, pattern: CellPattern.DATETIME },
TIME: { type: CellTypes.DATE, pattern: CellPatterns.TIME },
DATETIME: { type: CellTypes.DATE, pattern: CellPatterns.DATETIME },

TEXT: { type: CellType.TEXT, pattern: CellPattern.TEXT },
TEXT: { type: CellTypes.TEXT, pattern: CellPatterns.TEXT },

BOOLEAN: { type: CellType.BOOLEAN },
BOOLEAN: { type: CellTypes.BOOLEAN },
}

export interface FormatDefinition {
Expand Down

0 comments on commit bb44bad

Please sign in to comment.