node-pptx-parser 1.0.1 → 1.0.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Mirza-Glitch
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mirza-Glitch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.MD CHANGED
@@ -1,212 +1,212 @@
1
- # node-pptx-parser
2
-
3
- A Node.js library for parsing PowerPoint (PPTX) files and extracting text content. This library maintains text formatting, line breaks, and paragraph structures from the original presentation.
4
-
5
- ## Features
6
-
7
- - Extract text content from PPTX files with preserved formatting
8
-
9
- - Parse PPTX structure into manageable JavaScript objects
10
-
11
- - Access raw XML content of presentation components
12
-
13
- - Written in TypeScript for type safety
14
-
15
- - Promise-based API
16
-
17
- - Preserves line breaks and paragraph formatting
18
-
19
- - Minimal dependencies
20
-
21
- ## Installation
22
-
23
- ```bash
24
-
25
- npm install node-pptx-parser
26
- ```
27
-
28
- ## Usage
29
-
30
- Once the package is installed you can you it with `import` or `require` statements like this:
31
-
32
- ```javascript
33
- // ESM import:
34
- import PptxParser from "node-pptx-parser";
35
-
36
- // CommonJs require:
37
- const PptxParser = require("node-pptx-parser").default;
38
- ```
39
-
40
- ### Basic Text Extraction
41
-
42
- ```typescript
43
- import PptxParser from "node-pptx-parser";
44
-
45
- async function main() {
46
- const parser = new PptxParser("presentation.pptx");
47
-
48
- try {
49
- // Extract text from all slides
50
- const textContent = await parser.extractText();
51
-
52
- // Print text from each slide
53
- textContent.forEach((slide) => {
54
- console.log(`\nSlide ${slide.id}:`);
55
-
56
- console.log(slide.text.join("\n"));
57
- });
58
- } catch (error) {
59
- console.error("Error:", error.message);
60
- }
61
- }
62
-
63
- main();
64
- ```
65
-
66
- ### Advanced Usage - Full Presentation Parsing
67
-
68
- ```typescript
69
- import PptxParser from "node-pptx-parser";
70
-
71
- async function main() {
72
- const parser = new PptxParser("presentation.pptx");
73
-
74
- try {
75
- // Get complete parsed presentation content
76
- const parsedContent = await parser.parse();
77
-
78
- // Access presentation structure
79
- console.log(parsedContent.presentation.parsed);
80
-
81
- // Access individual slides
82
- parsedContent.slides.forEach((slide) => {
83
- console.log(`Slide ${slide.id}:`, slide.parsed);
84
- });
85
-
86
- // Access raw XML if needed
87
- console.log(parsedContent.presentation.xml);
88
- } catch (error) {
89
- console.error("Error:", error.message);
90
- }
91
- }
92
-
93
- main();
94
- ```
95
-
96
- ## API Reference
97
-
98
- ### `PptxParser`
99
-
100
- The main class for parsing PPTX files.
101
-
102
- #### Constructor
103
-
104
- ```typescript
105
-
106
- constructor(filePath: string)
107
- ```
108
-
109
- Creates a new instance of PptxParser.
110
-
111
- - `filePath`: Path to the PPTX file to be parsed
112
-
113
- #### Methods
114
-
115
- ##### `parse()`
116
-
117
- ```typescript
118
-
119
- async parse(): Promise<ParsedPresentation>
120
- ```
121
-
122
- Parses the entire PPTX file and returns its content.
123
-
124
- - Returns: Promise resolving to a `ParsedPresentation` object containing the complete presentation structure
125
-
126
- ##### `extractText()`
127
-
128
- ```typescript
129
-
130
- async extractText(): Promise<SlideTextContent[]>
131
- ```
132
-
133
- Extracts formatted text content from all slides.
134
-
135
- - Returns: Promise resolving to an array of `SlideTextContent` objects
136
-
137
- ### Types
138
-
139
- #### `ParsedPresentation`
140
-
141
- ```typescript
142
- interface ParsedPresentation {
143
- presentation: {
144
- path: string;
145
- xml: string;
146
- parsed: any;
147
- };
148
- relationships: {
149
- path: string;
150
- xml: string;
151
- parsed: any;
152
- };
153
- slides: ParsedSlide[];
154
- }
155
- ```
156
-
157
- #### `ParsedSlide`
158
-
159
- ```typescript
160
- interface ParsedSlide {
161
- id: string;
162
- path: string;
163
- xml: string;
164
- parsed: any;
165
- }
166
- ```
167
-
168
- #### `SlideTextContent`
169
-
170
- ```typescript
171
- interface SlideTextContent extends ParsedSlide {
172
- text: string[];
173
- }
174
- ```
175
-
176
- ## Error Handling
177
-
178
- The library throws errors in the following cases:
179
-
180
- - Invalid PPTX file structure
181
-
182
- - File reading errors
183
-
184
- - XML parsing errors
185
-
186
- Example error handling:
187
-
188
- ```typescript
189
- try {
190
- const parser = new PptxParser("presentation.ppt");
191
- const content = await parser.extractText();
192
- } catch (error) {
193
- if (error.message.includes("Invalid PPTX file structure")) {
194
- console.error("The PPTX file is corrupted or invalid");
195
- } else {
196
- console.error("An error occurred:", error.message);
197
- }
198
- }
199
- ```
200
-
201
- ## Dependencies
202
-
203
- - unzipper: For extracting PPTX files
204
- - xml2js: For parsing XML content
205
-
206
- ## License
207
-
208
- MIT
209
-
210
- ## Contributing
211
-
212
- Contributions are welcome! Please feel free to submit a Pull Request.
1
+ # node-pptx-parser
2
+
3
+ [![npm downloads](https://img.shields.io/npm/dm/node-pptx-parser)](https://www.npmjs.com/package/node-pptx-parser)
4
+ [![License](https://img.shields.io/npm/l/node-pptx-parser)](https://github.com/Mirza-Glitch/node-pptx-parser/blob/main/LICENSE)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
6
+
7
+ A Node.js library for parsing PowerPoint (PPTX) files and extracting text content. This library maintains text formatting, line breaks, and paragraph structures from the original presentation.
8
+
9
+ ## Features
10
+
11
+ - Extract text content from PPTX files with preserved formatting
12
+
13
+ - Parse PPTX structure into manageable JavaScript objects
14
+
15
+ - Access raw XML content of presentation components
16
+
17
+ - Written in TypeScript for type safety
18
+
19
+ - Promise-based API
20
+
21
+ - Preserves line breaks and paragraph formatting
22
+
23
+ - Minimal dependencies
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+
29
+ npm install node-pptx-parser
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Once the package is installed you can you it with `import` or `require` statements like this:
35
+
36
+ ```javascript
37
+ // ESM import:
38
+ import PptxParser from "node-pptx-parser";
39
+
40
+ // CommonJs require:
41
+ const PptxParser = require("node-pptx-parser").default;
42
+ ```
43
+
44
+ ### Basic Text Extraction
45
+
46
+ ```typescript
47
+ import PptxParser from "node-pptx-parser";
48
+
49
+ async function main() {
50
+ const parser = new PptxParser("presentation.pptx");
51
+
52
+ try {
53
+ // Extract text from all slides
54
+ const textContent = await parser.extractText();
55
+
56
+ // Print text from each slide
57
+ textContent.forEach((slide) => {
58
+ console.log(`\nSlide ${slide.id}:`);
59
+
60
+ console.log(slide.text.join("\n"));
61
+ });
62
+ } catch (error) {
63
+ console.error("Error:", error.message);
64
+ }
65
+ }
66
+
67
+ main();
68
+ ```
69
+
70
+ ### Advanced Usage - Full Presentation Parsing
71
+
72
+ ```typescript
73
+ import PptxParser from "node-pptx-parser";
74
+
75
+ async function main() {
76
+ const parser = new PptxParser("presentation.pptx");
77
+
78
+ try {
79
+ // Get complete parsed presentation content
80
+ const parsedContent = await parser.parse();
81
+
82
+ // Access presentation structure
83
+ console.log(parsedContent.presentation.parsed);
84
+
85
+ // Access individual slides
86
+ parsedContent.slides.forEach((slide) => {
87
+ console.log(`Slide ${slide.id}:`, slide.parsed);
88
+ });
89
+
90
+ // Access raw XML if needed
91
+ console.log(parsedContent.presentation.xml);
92
+ } catch (error) {
93
+ console.error("Error:", error.message);
94
+ }
95
+ }
96
+
97
+ main();
98
+ ```
99
+
100
+ ## API Reference
101
+
102
+ ### `PptxParser`
103
+
104
+ The main class for parsing PPTX files.
105
+
106
+ #### Constructor
107
+
108
+ ```typescript
109
+
110
+ constructor(filePath: string)
111
+ ```
112
+
113
+ Creates a new instance of PptxParser.
114
+
115
+ - `filePath`: Path to the PPTX file to be parsed
116
+
117
+ #### Methods
118
+
119
+ ##### `parse()`
120
+
121
+ ```typescript
122
+
123
+ async parse(): Promise<ParsedPresentation>
124
+ ```
125
+
126
+ Parses the entire PPTX file and returns its content.
127
+
128
+ - Returns: Promise resolving to a `ParsedPresentation` object containing the complete presentation structure
129
+
130
+ ##### `extractText()`
131
+
132
+ ```typescript
133
+
134
+ async extractText(): Promise<SlideTextContent[]>
135
+ ```
136
+
137
+ Extracts formatted text content from all slides.
138
+
139
+ - Returns: Promise resolving to an array of `SlideTextContent` objects
140
+
141
+ ### Types
142
+
143
+ #### `ParsedPresentation`
144
+
145
+ ```typescript
146
+ interface ParsedPresentation {
147
+ presentation: {
148
+ path: string;
149
+ xml: string;
150
+ parsed: any;
151
+ };
152
+ relationships: {
153
+ path: string;
154
+ xml: string;
155
+ parsed: any;
156
+ };
157
+ slides: ParsedSlide[];
158
+ }
159
+ ```
160
+
161
+ #### `ParsedSlide`
162
+
163
+ ```typescript
164
+ interface ParsedSlide {
165
+ id: string;
166
+ path: string;
167
+ xml: string;
168
+ parsed: any;
169
+ }
170
+ ```
171
+
172
+ #### `SlideTextContent`
173
+
174
+ ```typescript
175
+ interface SlideTextContent extends ParsedSlide {
176
+ text: string[];
177
+ }
178
+ ```
179
+
180
+ ## Error Handling
181
+
182
+ The library throws errors in the following cases:
183
+
184
+ - Invalid PPTX file structure
185
+
186
+ - File reading errors
187
+
188
+ - XML parsing errors
189
+
190
+ Example error handling:
191
+
192
+ ```typescript
193
+ try {
194
+ const parser = new PptxParser("presentation.ppt");
195
+ const content = await parser.extractText();
196
+ } catch (error) {
197
+ if (error.message.includes("Invalid PPTX file structure")) {
198
+ console.error("The PPTX file is corrupted or invalid");
199
+ } else {
200
+ console.error("An error occurred:", error.message);
201
+ }
202
+ }
203
+ ```
204
+
205
+ ## Dependencies
206
+
207
+ - unzipper: For extracting PPTX files
208
+ - xml2js: For parsing XML content
209
+
210
+ ## Contributing
211
+
212
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,87 @@
1
+ import type { ParsedPresentation, SlideTextContent } from "./types.mjs";
2
+ /**
3
+ * PptxParser - A class for parsing PowerPoint (PPTX) files and extracting their content
4
+ *
5
+ * This parser can:
6
+ * - Extract raw XML content from PPTX files
7
+ * - Parse the XML into JavaScript objects
8
+ * - Extract formatted text content from slides
9
+ * - Preserve line breaks and paragraph formatting
10
+ *
11
+ * PPTX files are essentially ZIP archives containing XML files. The main files we care about are:
12
+ * - presentation.xml: Contains the main presentation structure
13
+ * - _rels/presentation.xml.rels: Contains relationships between presentation parts
14
+ * - slides/slide*.xml: Contains individual slide content
15
+ */
16
+ export default class PptxParser {
17
+ private filePath;
18
+ /**
19
+ * Creates a new instance of PptxParser
20
+ * @param filePath - Path to the PPTX file to be parsed
21
+ */
22
+ constructor(filePath: string);
23
+ /**
24
+ * Parses the entire PPTX file and returns its content
25
+ *
26
+ * This method:
27
+ * 1. Opens the PPTX file as a ZIP archive
28
+ * 2. Extracts and parses the presentation.xml
29
+ * 3. Extracts and parses the relationship file
30
+ * 4. Finds and parses all slides
31
+ *
32
+ * @returns Promise<ParsedPresentation> - Object containing parsed presentation data
33
+ * @throws Error if the PPTX file is invalid or cannot be parsed
34
+ */
35
+ parse(): Promise<ParsedPresentation>;
36
+ /**
37
+ * Extracts content from a file within the PPTX archive
38
+ *
39
+ * @param file - A file from the unzipper library
40
+ * @returns Promise<string> - The file's content as a string
41
+ */
42
+ private getFileContent;
43
+ /**
44
+ * Parses XML content into a JavaScript object
45
+ *
46
+ * @param xmlContent - Raw XML string to parse
47
+ * @returns Promise<any> - Parsed JavaScript object
48
+ */
49
+ private parseXmlContent;
50
+ /**
51
+ * Extracts slide relations from the presentation relationships XML
52
+ *
53
+ * In PPTX files, slides are referenced by relationships in the presentation.xml.rels file.
54
+ * This method finds all slide references in these relationships.
55
+ *
56
+ * @param relationshipsData - Parsed relationship XML data
57
+ * @returns SlideRelation[] - Array of slide relations
58
+ */
59
+ private getSlideRelations;
60
+ /**
61
+ * Extracts formatted text content from all slides
62
+ *
63
+ * This is a convenience method that:
64
+ * 1. Parses the entire presentation
65
+ * 2. Extracts text from each slide
66
+ * 3. Preserves formatting and line breaks
67
+ *
68
+ * @returns Promise<SlideTextContent[]> - Array of slide text content
69
+ */
70
+ extractText(): Promise<SlideTextContent[]>;
71
+ /**
72
+ * Extracts text content from a single slide while preserving formatting
73
+ *
74
+ * PowerPoint slide XML structure:
75
+ * - p:sp: Shape elements that can contain text
76
+ * - p:txBody: The text body within a shape
77
+ * - a:p: Individual paragraphs
78
+ * - a:r: Text runs within paragraphs
79
+ * - a:t: Actual text content
80
+ * - a:br: Line breaks
81
+ * - a:endParaRPr: Paragraph end markers
82
+ *
83
+ * @param slideData - Parsed slide XML data
84
+ * @returns string[] - Array of text blocks with preserved formatting
85
+ */
86
+ private extractTextFromSlide;
87
+ }
@@ -0,0 +1,26 @@
1
+ export interface SlideRelation {
2
+ id: string;
3
+ target: string;
4
+ }
5
+ export interface ParsedSlide {
6
+ id: string;
7
+ path: string;
8
+ xml: string;
9
+ parsed: any;
10
+ }
11
+ export interface ParsedPresentation {
12
+ presentation: {
13
+ path: string;
14
+ xml: string;
15
+ parsed: any;
16
+ };
17
+ relationships: {
18
+ path: string;
19
+ xml: string;
20
+ parsed: any;
21
+ };
22
+ slides: ParsedSlide[];
23
+ }
24
+ export interface SlideTextContent extends ParsedSlide {
25
+ text: string[];
26
+ }
@@ -1,4 +1,4 @@
1
- import { ParsedPresentation, SlideTextContent } from "./types";
1
+ import type { ParsedPresentation, SlideTextContent } from "./types.js";
2
2
  /**
3
3
  * PptxParser - A class for parsing PowerPoint (PPTX) files and extracting their content
4
4
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-pptx-parser",
3
- "version": "1.0.01",
3
+ "version": "1.0.2",
4
4
  "description": "A PowerPoint (PPTX) parser that extracts text content with preserved formatting",
5
5
  "homepage": "https://github.com/Mirza-Glitch/node-pptx-parser.git",
6
6
  "repository": {
@@ -20,9 +20,14 @@
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "exports": {
22
22
  ".": {
23
- "require": "./dist/cjs/index.js",
24
- "import": "./dist/esm/index.mjs",
25
- "types": "./dist/types/index.d.ts"
23
+ "import": {
24
+ "types": "./dist/esm/index.d.mts",
25
+ "default": "./dist/esm/index.mjs"
26
+ },
27
+ "require": {
28
+ "types": "./dist/types/index.d.ts",
29
+ "default": "./dist/cjs/index.js"
30
+ }
26
31
  }
27
32
  },
28
33
  "scripts": {
@@ -30,7 +35,8 @@
30
35
  "build:esm": "tsc -p tsconfig.esm.json && npm run rename:esm",
31
36
  "build": "npm run build:cjs && npm run build:esm",
32
37
  "clean": "rimraf dist",
33
- "rename:esm": "bash ./scripts/fix-mjs.sh",
38
+ "rename:esm": "node ./scripts/fix-mjs.mjs",
39
+ "test:package": "npm run clean && npm run build && tsc -p tests/tsconfig.json && tsc -p tests/tsconfig.json --module node16 --moduleResolution node16 && node tests/runtime.mjs",
34
40
  "prepack": "npm run clean && npm run build"
35
41
  },
36
42
  "dependencies": {