Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88c5560

Browse files
securedeveloperafzalah
authored andcommitted
JSE [feat] code refactor, getISOFormattedDate and complete structure for docProps directory.
1 parent 59d92aa commit 88c5560

File tree

10 files changed

+589
-68
lines changed

10 files changed

+589
-68
lines changed

‎src/api/Helper.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
export function cleanAlphaNumericString(str: string): string {
22
return str ? str.replace(/\W/g, '') : str;
33
}
4+
5+
export function getISOFormattedDate(date?: Date): string {
6+
if (!date) {
7+
date = new Date();
8+
}
9+
10+
return date.toISOString().split('.')[0] + "Z";
11+
}

‎src/api/Internals.ts‎

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,66 @@
1-
export const Xmlns_Types: string = "http://schemas.openxmlformats.org/package/2006/content-types";
2-
export const Xmlns_RelationShips: string = "http://schemas.openxmlformats.org/package/2006/relationships";
3-
export const Extension_Rels: string = "application/vnd.openxmlformats-package.relationships+xml";
4-
export const Extension_Xml: string = "application/xml";
5-
export const PartName_Xl_Workbook: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
6-
export const PartName_Xl_Sheet: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
7-
export const PartName_Xl_Theme: string = "application/vnd.openxmlformats-officedocument.theme+xm";
8-
export const PartName_Xl_Styles: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml";
9-
export const PartName_Xl_SharedStrings: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
10-
export const PartName_DocProps_Core: string = "application/vnd.openxmlformats-package.core-properties+xml";
11-
export const PartName_DocProps_App: string = "application/vnd.openxmlformats-officedocument.extended-properties+xml";
12-
export const PartName_DocProps_Custom: string = "application/vnd.openxmlformats-officedocument.custom-properties+xml";
13-
export const Relationship_Type_App: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
14-
export const Relationship_Type_Core: string = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
15-
export const Relationship_Type_Custom: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";
16-
export const Relationship_Type_Workbook: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
17-
export const Relationship_Target_App: string = "docProps/app.xml";
18-
export const Relationship_Target_Core: string = "docProps/core.xml";
19-
export const Relationship_Target_Custom: string = "xl/workbook.xml";
20-
export const Relationship_Target_Workbook: string = "docProps/custom.xml";
1+
export const XMLNS_CONTENT_TYPES: string = "http://schemas.openxmlformats.org/package/2006/content-types";
2+
export const XMLNS_RELATIONSHIPS: string = "http://schemas.openxmlformats.org/package/2006/relationships";
3+
export const XMLNS_EXTENDED_PROPERTIES: string = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
4+
export const XMLNS_CUSTOM_PROPERTIES: string = "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties";
5+
export const XMLNS_METADATA_CORE_PROPERTIES: string = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
6+
export const XMLNS_DC_CORE_PROPERTIES: string = "http://purl.org/dc/elements/1.1/";
7+
export const XMLNS_DC_TERMS_CORE_PROPERTIES: string = "http://purl.org/dc/terms/";
8+
export const XMLNS_DCMI_TYPE_CORE_PROPERTIES: string = "http://purl.org/dc/dcmitype/";
9+
export const XMLNS_XSI_XML_SCHEMA_INSTANCE: string = "http://www.w3.org/2001/XMLSchema-instance";
10+
export const XMLNS_DOC_PROPS_V_TYPES: string = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes";
11+
export const EXTENSION_RELS_SCHEMA: string = "application/vnd.openxmlformats-package.relationships+xml";
12+
export const EXTENSION_XML_SCHEMA: string = "application/xml";
13+
export const PART_NAME_XL_WORKBOOK: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
14+
export const PART_NAME_XL_WORKSHEET: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
15+
export const PART_NAME_XL_THEME: string = "application/vnd.openxmlformats-officedocument.theme+xm";
16+
export const PART_NAME_XL_STYLES: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml";
17+
export const PART_NAME_XL_SHARED_STRINGS: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
18+
export const PART_NAME_DOC_PROPS_CORE: string = "application/vnd.openxmlformats-package.core-properties+xml";
19+
export const PART_NAME_DOC_PROPS_APP: string = "application/vnd.openxmlformats-officedocument.extended-properties+xml";
20+
export const PART_NAME_DOC_PROPS_CUSTOM: string = "application/vnd.openxmlformats-officedocument.custom-properties+xml";
21+
export const RELATIONSHIP_TYPE_APP: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
22+
export const RELATIONSHIP_TYPE_CORE: string = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
23+
export const RELATIONSHIP_TYPE_CUSTOM: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";
24+
export const RELATION_TYPE_WORKBOOK: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
25+
export const RELATIONSHIP_TARGET_APP: string = "docProps/app.xml";
26+
export const RELATIONSHIP_TARGET_CORE: string = "docProps/core.xml";
27+
export const RELATIONSHIP_TARGET_CUSTOM: string = "xl/workbook.xml";
28+
export const RELATIONSHIP_TARGET_WORKBOOK: string = "docProps/custom.xml";
29+
30+
31+
/**
32+
* Defaults for Internal use
33+
* */
34+
export const ENCODING_UTF_8: string = "UTF-8";
35+
export const DEFAULT_XML_VERSION: string = "1.0";
36+
export const DEFAULT_STAND_ALONE: boolean = true;
37+
export const DEFAULT_APPLICATION: string = "Microsoft Excel";
38+
export const DEFAULT_DOC_SECURITY: number = 0;
39+
export const DEFAULT_SCALE_CROP: boolean = false;
40+
export const DEFAULT_WORKSHEETS: string = "Worksheets";
41+
export const DEFAULT_PUB_DATA: string = "PubData";
42+
export const DEFAULT_MANAGER: string = "javascript-excel";
43+
export const DEFAULT_COMPANY: string = "javascript-excel";
44+
export const DEFAULT_LINKS_UPTO_DATE: boolean = false;
45+
export const DEFAULT_SHARED_DOC: boolean = false;
46+
export const DEFAULT_HYPER_LINKS_CHANGED: boolean = false;
47+
export const DEFAULT_APP_VERSION: string = "16.0300";
48+
export const DEFAULT_HYPER_LINK_BASE: string = "https://github.com/securedeveloper/javascript-excel";
49+
export const DEFAULT_PROPS_TITLE: string = "JSE Excel File";
50+
export const DEFAULT_PROPS_SUBJECT: string = "JSE Excel File";
51+
export const DEFAULT_PROPS_CREATOR: string = "javascript-excel";
52+
export const DEFAULT_PROPS_KEYWORDS: string = "javascript-excel";
53+
export const DEFAULT_PROPS_DESCRIPTION: string = "Excel file built with the help of javascript-excel API";
54+
export const DEFAULT_PROPS_LAST_MODIFIED_BY: string = "javascript-excel";
55+
export const DEFAULT_PROPS_CATEGORY: string = "javascript api";
56+
57+
/**
58+
* Files, Extensions and Directories
59+
*/
60+
export const FILE_APP: string = "app";
61+
export const FILE_CORE: string = "core";
62+
export const FILE_CUSTOM: string = "custom";
63+
export const FILE_RELS: string = "_rels";
64+
export const EXTENSION_XML: string = ".xml";
65+
export const EXTENSION_RELS: string = ".rels";
66+
export const DIRECTORY_DOC_PROPS: string = "docProps";

‎src/api/xlsx.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ interface ___JSE_XLSX___XMLTag {
7878

7979
interface ___JSE_XLSX___NodeAttribute {
8080
key: string | ___JSE_XLSX___NodeKey; // TODO: Make precise if possible
81-
value: string; // TODO: Improve if needed
81+
value: string|number|boolean; // TODO: Improve if needed
8282
}
8383

8484
export interface ___JSE_XLSX___Node {
8585
name: string | ___JSE_XLSX___NodeName; // TODO: Make Precise if possible
8686
values?: Array<___JSE_XLSX___NodeAttribute>;
87-
content?: ___JSE_XLSX___Node | Array<___JSE_XLSX___Node>;
87+
content?: ___JSE_XLSX___Node | Array<___JSE_XLSX___Node>|string|number|boolean;
8888
}
8989

9090
export interface ___JSE_XLSX___FileContent {

‎src/xlsx/FileContentTypes.ts‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import {___JSE_XLSX___File, ___JSE_XLSX___FileContent, ___JSE_XLSX___Node} from "../api/xlsx";
22
import {
3-
Extension_Rels,
4-
Extension_Xml, PartName_DocProps_App, PartName_DocProps_Core, PartName_DocProps_Custom, PartName_Xl_SharedStrings,
5-
PartName_Xl_Sheet, PartName_Xl_Styles,
6-
PartName_Xl_Theme,
7-
PartName_Xl_Workbook,
8-
Xmlns_Types
3+
EXTENSION_RELS_SCHEMA,
4+
EXTENSION_XML_SCHEMA,
5+
PART_NAME_DOC_PROPS_APP,
6+
PART_NAME_DOC_PROPS_CORE,
7+
PART_NAME_DOC_PROPS_CUSTOM,
8+
PART_NAME_XL_SHARED_STRINGS,
9+
PART_NAME_XL_WORKSHEET,
10+
PART_NAME_XL_STYLES,
11+
PART_NAME_XL_THEME,
12+
PART_NAME_XL_WORKBOOK,
13+
XMLNS_CONTENT_TYPES,
14+
DEFAULT_XML_VERSION, ENCODING_UTF_8, DEFAULT_STAND_ALONE
915
} from "../api/Internals";
1016
import {JSESheet, JSExcel} from "../Types";
17+
import {DEFAULT_FILE_EXTENSION} from "../api/constants";
1118

1219
const fileProps: any = {
1320
name: "[Content_Types]",
14-
extension: ".xml",
15-
version: "1.0",
16-
encoding: "UTF-8",
17-
standalone: true,
21+
extension: DEFAULT_FILE_EXTENSION,
22+
version: DEFAULT_XML_VERSION,
23+
encoding: ENCODING_UTF_8,
24+
standalone: DEFAULT_STAND_ALONE,
1825
nodes: {
1926
Types: "Types",
2027
Default: "Default",
@@ -48,22 +55,22 @@ function getContentTypeNodes(excel: JSExcel): ___JSE_XLSX___FileContent {
4855
},
4956
content: {
5057
name: fileProps.nodes.Types,
51-
values: [{key: fileProps.keys.xmlns, value: Xmlns_Types}],
58+
values: [{key: fileProps.keys.xmlns, value: XMLNS_CONTENT_TYPES}],
5259
content: [
5360
{
5461
name: fileProps.nodes.Default,
5562
values:
5663
[
5764
{key: fileProps.keys.Extension, value: fileProps.values.rels},
58-
{key: fileProps.keys.ContentType, value: Extension_Rels}
65+
{key: fileProps.keys.ContentType, value: EXTENSION_RELS_SCHEMA}
5966
]
6067
},
6168
{
6269
name: fileProps.nodes.Default,
6370
values:
6471
[
6572
{key: fileProps.keys.Extension, value: fileProps.values.xml},
66-
{key: fileProps.keys.ContentType, value: Extension_Xml}
73+
{key: fileProps.keys.ContentType, value: EXTENSION_XML_SCHEMA}
6774
]
6875
},
6976
//xl folder contents
@@ -73,7 +80,7 @@ function getContentTypeNodes(excel: JSExcel): ___JSE_XLSX___FileContent {
7380
values:
7481
[
7582
{key: fileProps.keys.PartName, value: fileProps.values.PartName_xml},
76-
{key: fileProps.keys.ContentType, value: PartName_Xl_Workbook}
83+
{key: fileProps.keys.ContentType, value: PART_NAME_XL_WORKBOOK}
7784
]
7885
},
7986
...getWorkSheetsOverrides(excel),
@@ -93,7 +100,7 @@ function getWorkSheetsOverrides(excel: JSExcel): Array<___JSE_XLSX___Node> {
93100
name: fileProps.nodes.Override,
94101
values: [
95102
{key: fileProps.keys.PartName, value: `${partNameOverride}${sheet.name}${fileProps.extension}`},
96-
{key: fileProps.keys.ContentType, value: PartName_Xl_Sheet}
103+
{key: fileProps.keys.ContentType, value: PART_NAME_XL_WORKSHEET}
97104
]
98105
}));
99106
}
@@ -106,7 +113,7 @@ function getThemesOverrides(excel: JSExcel): Array<___JSE_XLSX___Node> {
106113
name: fileProps.nodes.Override,
107114
values: [
108115
{key: fileProps.keys.PartName, value: `${partNameOverride}theme1${fileProps.extension}`},
109-
{key: fileProps.keys.ContentType, value: PartName_Xl_Theme}
116+
{key: fileProps.keys.ContentType, value: PART_NAME_XL_THEME}
110117
]
111118
}];
112119
}
@@ -119,7 +126,7 @@ function getStylesOverrides(excel: JSExcel): Array<___JSE_XLSX___Node> {
119126
name: fileProps.nodes.Override,
120127
values: [
121128
{key: fileProps.keys.PartName, value: `${partNameOverride}${fileProps.extension}`},
122-
{key: fileProps.keys.ContentType, value: PartName_Xl_Styles}
129+
{key: fileProps.keys.ContentType, value: PART_NAME_XL_STYLES}
123130
]
124131
}];
125132
}
@@ -132,7 +139,7 @@ function getSharedStringsOverrides(excel: JSExcel): Array<___JSE_XLSX___Node> {
132139
name: fileProps.nodes.Override,
133140
values: [
134141
{key: fileProps.keys.PartName, value: `${partNameOverride}${fileProps.extension}`},
135-
{key: fileProps.keys.ContentType, value: PartName_Xl_SharedStrings}
142+
{key: fileProps.keys.ContentType, value: PART_NAME_XL_SHARED_STRINGS}
136143
]
137144
}];
138145
}
@@ -145,14 +152,14 @@ function getPropsOverrides(excel: JSExcel): Array<___JSE_XLSX___Node> {
145152
name: fileProps.nodes.Override,
146153
values: [
147154
{key: fileProps.keys.PartName, value: `${partNameOverride}core${fileProps.extension}`},
148-
{key: fileProps.keys.ContentType, value: PartName_DocProps_Core}
155+
{key: fileProps.keys.ContentType, value: PART_NAME_DOC_PROPS_CORE}
149156
]
150157
},
151158
{
152159
name: fileProps.nodes.Override,
153160
values: [
154161
{key: fileProps.keys.PartName, value: `${partNameOverride}app${fileProps.extension}`},
155-
{key: fileProps.keys.ContentType, value: PartName_DocProps_App}
162+
{key: fileProps.keys.ContentType, value: PART_NAME_DOC_PROPS_APP}
156163
]
157164
},
158165
// ...getCustomPropsOverrider(excel) TODO: Implement when doc props interface is available and only custom props are provided
@@ -168,7 +175,7 @@ function getCustomPropsOverrider(excel: JSExcel): ___JSE_XLSX___Node {
168175
name: fileProps.nodes.Override,
169176
values: [
170177
{key: fileProps.keys.PartName, value: `${partNameOverride}${fileProps.extension}`},
171-
{key: fileProps.keys.ContentType, value: PartName_DocProps_Custom}
178+
{key: fileProps.keys.ContentType, value: PART_NAME_DOC_PROPS_CUSTOM}
172179
]
173180
};
174181
}

‎src/xlsx/_rels/DirectoryRels.ts‎

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
import {JSExcel} from "../../Types";
2-
import {___JSE_XLSX___Directory, ___JSE_XLSX___File, ___JSE_XLSX___FileContent, ___JSE_XLSX___Node} from "../../api/xlsx";
32
import {
4-
Relationship_Target_App,
5-
Relationship_Target_Core,
6-
Relationship_Target_Custom,
7-
Relationship_Target_Workbook,
8-
Relationship_Type_App,
9-
Relationship_Type_Core,
10-
Relationship_Type_Custom,
11-
Relationship_Type_Workbook,
12-
Xmlns_RelationShips
3+
___JSE_XLSX___Directory,
4+
___JSE_XLSX___File,
5+
___JSE_XLSX___FileContent,
6+
___JSE_XLSX___Node
7+
} from "../../api/xlsx";
8+
import {
9+
RELATIONSHIP_TARGET_APP,
10+
RELATIONSHIP_TARGET_CORE,
11+
RELATIONSHIP_TARGET_CUSTOM,
12+
RELATIONSHIP_TARGET_WORKBOOK,
13+
RELATIONSHIP_TYPE_APP,
14+
RELATIONSHIP_TYPE_CORE,
15+
RELATIONSHIP_TYPE_CUSTOM,
16+
RELATION_TYPE_WORKBOOK,
17+
XMLNS_RELATIONSHIPS,
18+
EXTENSION_RELS,
19+
DEFAULT_XML_VERSION,
20+
ENCODING_UTF_8,
21+
DEFAULT_STAND_ALONE, FILE_RELS
1322
} from "../../api/Internals";
1423

1524
const fileProps: any = {
1625
name: null,
17-
extension: ".rels",
18-
version: "1.0",
19-
encoding: "UTF-8",
20-
standalone: true,
26+
extension: EXTENSION_RELS,
27+
version: DEFAULT_XML_VERSION,
28+
encoding: ENCODING_UTF_8,
29+
standalone: DEFAULT_STAND_ALONE,
2130
nodes: {
2231
Relationships: "Relationships",
2332
Relationship: "Relationship"
@@ -37,7 +46,7 @@ const fileProps: any = {
3746
};
3847

3948
const directorProps: any = {
40-
name: "_rels",
49+
name: FILE_RELS,
4150
files: {rels: {...fileProps}}
4251
};
4352

@@ -63,30 +72,30 @@ function getRelsNodes(excel: JSExcel): ___JSE_XLSX___FileContent {
6372
},
6473
content: {
6574
name: fileProps.nodes.Relationships,
66-
values: [{key: fileProps.keys.xmlns, value: Xmlns_RelationShips}],
75+
values: [{key: fileProps.keys.xmlns, value: XMLNS_RELATIONSHIPS}],
6776
content: [
6877
{
6978
name: fileProps.nodes.Relationship,
7079
values: [
7180
{key: fileProps.keys.Id, value: fileProps.values.Id_rId3},
72-
{key: fileProps.keys.Type, value: Relationship_Type_App},
73-
{key: fileProps.keys.Target, value: Relationship_Target_App}
81+
{key: fileProps.keys.Type, value: RELATIONSHIP_TYPE_APP},
82+
{key: fileProps.keys.Target, value: RELATIONSHIP_TARGET_APP}
7483
]
7584
},
7685
{
7786
name: fileProps.nodes.Relationship,
7887
values: [
7988
{key: fileProps.keys.Id, value: fileProps.values.Id_rId2},
80-
{key: fileProps.keys.Type, value: Relationship_Type_Core},
81-
{key: fileProps.keys.Target, value: Relationship_Target_Core}
89+
{key: fileProps.keys.Type, value: RELATIONSHIP_TYPE_CORE},
90+
{key: fileProps.keys.Target, value: RELATIONSHIP_TARGET_CORE}
8291
]
8392
},
8493
{
8594
name: fileProps.nodes.Relationship,
8695
values: [
8796
{key: fileProps.keys.Id, value: fileProps.values.Id_rId1},
88-
{key: fileProps.keys.Type, value: Relationship_Type_Workbook},
89-
{key: fileProps.keys.Target, value: Relationship_Target_Workbook}
97+
{key: fileProps.keys.Type, value: RELATION_TYPE_WORKBOOK},
98+
{key: fileProps.keys.Target, value: RELATIONSHIP_TARGET_WORKBOOK}
9099
]
91100
},
92101
// ...getCustomRelationshipNode(excel) TODO: finish when file custom props are implemented
@@ -101,8 +110,8 @@ function getCustomRelationshipNode(excel: JSExcel): ___JSE_XLSX___Node {
101110
name: fileProps.nodes.Relationship,
102111
values: [
103112
{key: fileProps.keys.Id, value: fileProps.values.Id_rId4},
104-
{key: fileProps.keys.Type, value: Relationship_Type_Custom},
105-
{key: fileProps.keys.Target, value: Relationship_Target_Custom}
113+
{key: fileProps.keys.Type, value: RELATIONSHIP_TYPE_CUSTOM},
114+
{key: fileProps.keys.Target, value: RELATIONSHIP_TARGET_CUSTOM}
106115
]
107116
};
108117
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// TODO: Tier-02 Replace values when file properties module is implemented
2+
import {JSExcel} from "../../Types";
3+
import {___JSE_XLSX___Directory, ___JSE_XLSX___File} from "../../api/xlsx";
4+
import {DIRECTORY_DOC_PROPS} from "../../api/Internals";
5+
import appFile from "./FileDocPropsApp";
6+
import coreFile from "./FileDocPropsCore";
7+
import customFile from "./FileDocPropsCustom";
8+
9+
const directoryProps: any = {
10+
name: DIRECTORY_DOC_PROPS
11+
};
12+
13+
export default (excel: JSExcel): ___JSE_XLSX___Directory => ({
14+
directoryName: directoryProps.name,
15+
content: getRelDirectoryFiles(excel)
16+
});
17+
18+
function getRelDirectoryFiles(excel: JSExcel): Array<___JSE_XLSX___File> {
19+
return [appFile(excel), coreFile(excel), customFile(excel)];
20+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /