mindee 4.31.1 → 4.32.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/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://opensource.org/licenses/MIT) [](https://opensource.org/licenses/MIT) [](https://github.com/mindee/mindee-api-nodejs) [](https://www.npmjs.com/package/mindee) [](https://www.npmjs.com/package/mindee)
|
|
2
2
|
|
|
3
3
|
# Mindee API Helper Library for Node.js
|
|
4
4
|
Quickly and easily connect to Mindee's API services using Node.js.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.32.0",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "bin/mindee.js",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"@types/mocha": "^10.0.10",
|
|
45
45
|
"@types/node": "^18.15.13",
|
|
46
46
|
"@types/tmp": "^0.2.6",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
48
|
-
"@typescript-eslint/parser": "^8.
|
|
49
|
-
"chai": "^4.
|
|
50
|
-
"eslint": "^9.
|
|
51
|
-
"eslint-plugin-jsdoc": "^50.
|
|
52
|
-
"mocha": "^11.7.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.42.1",
|
|
48
|
+
"@typescript-eslint/parser": "^8.42.1",
|
|
49
|
+
"chai": "^4.4.1",
|
|
50
|
+
"eslint": "^9.20.1",
|
|
51
|
+
"eslint-plugin-jsdoc": "^50.6.17",
|
|
52
|
+
"mocha": "^11.7.4",
|
|
53
53
|
"nock": "^13.5.6",
|
|
54
54
|
"ts-node": "^10.9.2",
|
|
55
|
-
"typedoc": "~0.28.
|
|
56
|
-
"typescript": "^5.
|
|
55
|
+
"typedoc": "~0.28.14",
|
|
56
|
+
"typescript": "^5.7.3"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@cantoo/pdf-lib": "^2.3.2",
|
|
@@ -11,6 +11,16 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
11
11
|
*/
|
|
12
12
|
protected constructor({ inputType }: InputConstructor);
|
|
13
13
|
protected checkMimetype(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the file object as a Buffer.
|
|
16
|
+
* @returns Buffer representation of the file object
|
|
17
|
+
* @protected
|
|
18
|
+
*/
|
|
19
|
+
protected getBuffer(): Buffer;
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether the current file is a PDF.
|
|
22
|
+
* @returns {boolean} Returns true if the file is a PDF; otherwise, returns false.
|
|
23
|
+
*/
|
|
14
24
|
isPdf(): boolean;
|
|
15
25
|
/**
|
|
16
26
|
* Cut PDF pages.
|
|
@@ -41,4 +51,10 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
41
51
|
* @return boolean
|
|
42
52
|
*/
|
|
43
53
|
hasSourceText(): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the number of pages in the input source.
|
|
56
|
+
* For PDFs, returns the actual page count. For images, returns 1.
|
|
57
|
+
* @return Promise<number> The number of pages
|
|
58
|
+
*/
|
|
59
|
+
getPageCount(): Promise<number>;
|
|
44
60
|
}
|
|
@@ -104,6 +104,21 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
104
104
|
logger_1.logger.debug(`File is of type: ${mimeType}`);
|
|
105
105
|
return mimeType;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns the file object as a Buffer.
|
|
109
|
+
* @returns Buffer representation of the file object
|
|
110
|
+
* @protected
|
|
111
|
+
*/
|
|
112
|
+
getBuffer() {
|
|
113
|
+
if (typeof this.fileObject === "string") {
|
|
114
|
+
return Buffer.from(this.fileObject);
|
|
115
|
+
}
|
|
116
|
+
return this.fileObject;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Determines whether the current file is a PDF.
|
|
120
|
+
* @returns {boolean} Returns true if the file is a PDF; otherwise, returns false.
|
|
121
|
+
*/
|
|
107
122
|
isPdf() {
|
|
108
123
|
if (!this.initialized) {
|
|
109
124
|
throw new Error("The `init()` method must be called before calling `isPdf()`.");
|
|
@@ -115,13 +130,9 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
115
130
|
* @param pageOptions
|
|
116
131
|
*/
|
|
117
132
|
async applyPageOptions(pageOptions) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (!(this.fileObject instanceof Buffer)) {
|
|
122
|
-
throw new Error(`Cannot modify an input source of type ${this.inputType}.`);
|
|
123
|
-
}
|
|
124
|
-
const processedPdf = await (0, pdf_2.extractPages)(this.fileObject, pageOptions);
|
|
133
|
+
await this.init();
|
|
134
|
+
const buffer = this.getBuffer();
|
|
135
|
+
const processedPdf = await (0, pdf_2.extractPages)(buffer, pageOptions);
|
|
125
136
|
this.fileObject = processedPdf.file;
|
|
126
137
|
}
|
|
127
138
|
/**
|
|
@@ -145,16 +156,8 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
145
156
|
* @returns A Promise that resolves when the compression is complete.
|
|
146
157
|
*/
|
|
147
158
|
async compress(quality = 85, maxWidth = null, maxHeight = null, forceSourceText = false, disableSourceText = true) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
let buffer;
|
|
152
|
-
if (typeof this.fileObject === "string") {
|
|
153
|
-
buffer = Buffer.from(this.fileObject);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
buffer = this.fileObject;
|
|
157
|
-
}
|
|
159
|
+
await this.init();
|
|
160
|
+
const buffer = this.getBuffer();
|
|
158
161
|
if (this.isPdf()) {
|
|
159
162
|
this.fileObject = await (0, pdf_1.compressPdf)(buffer, quality, forceSourceText, disableSourceText);
|
|
160
163
|
}
|
|
@@ -167,14 +170,25 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
167
170
|
* @return boolean
|
|
168
171
|
*/
|
|
169
172
|
async hasSourceText() {
|
|
170
|
-
|
|
171
|
-
await this.init();
|
|
172
|
-
}
|
|
173
|
+
await this.init();
|
|
173
174
|
if (!this.isPdf()) {
|
|
174
175
|
return false;
|
|
175
176
|
}
|
|
176
|
-
const buffer =
|
|
177
|
+
const buffer = this.getBuffer();
|
|
177
178
|
return (0, pdf_2.hasSourceText)(buffer);
|
|
178
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Returns the number of pages in the input source.
|
|
182
|
+
* For PDFs, returns the actual page count. For images, returns 1.
|
|
183
|
+
* @return Promise<number> The number of pages
|
|
184
|
+
*/
|
|
185
|
+
async getPageCount() {
|
|
186
|
+
await this.init();
|
|
187
|
+
if (!this.isPdf()) {
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
const buffer = this.getBuffer();
|
|
191
|
+
return (0, pdf_1.countPages)(buffer);
|
|
192
|
+
}
|
|
179
193
|
}
|
|
180
194
|
exports.LocalInputSource = LocalInputSource;
|
|
@@ -10,4 +10,9 @@ export interface SplitPdf {
|
|
|
10
10
|
* @returns the new cut pdf file.
|
|
11
11
|
*/
|
|
12
12
|
export declare function extractPages(file: Buffer, pageOptions: PageOptions): Promise<SplitPdf>;
|
|
13
|
+
/**
|
|
14
|
+
* Count the number of pages in a pdf file.
|
|
15
|
+
* @param file
|
|
16
|
+
* @returns the number of pages in the file.
|
|
17
|
+
*/
|
|
13
18
|
export declare function countPages(file: Buffer): Promise<number>;
|
package/src/pdf/pdfOperation.js
CHANGED
|
@@ -66,6 +66,11 @@ async function extractPages(file, pageOptions) {
|
|
|
66
66
|
const fileBuffer = Buffer.from(await newPdf.save());
|
|
67
67
|
return { file: fileBuffer, totalPagesRemoved: sumRemovedPages };
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Count the number of pages in a pdf file.
|
|
71
|
+
* @param file
|
|
72
|
+
* @returns the number of pages in the file.
|
|
73
|
+
*/
|
|
69
74
|
async function countPages(file) {
|
|
70
75
|
const currentPdf = await pdf_lib_1.PDFDocument.load(file, {
|
|
71
76
|
ignoreEncryption: true,
|