pdfium-native 0.3.1 → 0.4.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
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.4.0] - 2026-04-04
8
+
9
+ ### Added
10
+
11
+ - `concurrency()` — get/set max concurrent native operations dispatched to the libuv thread pool (default: CPU cores, powered by p-limit)
12
+ - Husky + lint-staged pre-commit hook (Prettier + ESLint on staged files)
13
+
7
14
  ## [0.3.0] - 2026-03-31
8
15
 
9
16
  ### Added
package/README.md CHANGED
@@ -365,6 +365,26 @@ interface DocumentMetadata {
365
365
 
366
366
  ---
367
367
 
368
+ ## ⚙️ Concurrency
369
+
370
+ ### `concurrency(value?): number`
371
+
372
+ Gets or sets the maximum number of concurrent native operations dispatched to the thread pool.
373
+
374
+ The default is the number of CPU cores (`os.availableParallelism()`). A value of `0` resets to the default.
375
+
376
+ PDFium is single-threaded internally — all operations are serialized through a global mutex. The concurrency limiter prevents excess libuv worker threads from being blocked waiting on that mutex.
377
+
378
+ ```typescript
379
+ import { loadDocument, concurrency } from 'pdfium-native';
380
+
381
+ concurrency(); // 8 (CPU cores)
382
+ concurrency(2); // limit to 2 concurrent operations
383
+ concurrency(0); // reset to default
384
+ ```
385
+
386
+ ---
387
+
368
388
  ## 🙏 Acknowledgements
369
389
 
370
390
  This project uses prebuilt PDFium binaries from [bblanchon/pdfium-binaries](https://github.com/bblanchon/pdfium-binaries), which provides automated builds of the PDFium library for multiple platforms. Thanks to [@bblanchon](https://github.com/bblanchon) for maintaining this invaluable resource.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Gets or sets the maximum number of concurrent native operations.
3
+ *
4
+ * The default value is the number of CPU cores (`os.availableParallelism()`).
5
+ * A value of `0` resets to the default.
6
+ */
7
+ export declare function concurrency(value?: number): number;
8
+ export declare function withConcurrency<T>(fn: () => Promise<T>): Promise<T>;
9
+ //# sourceMappingURL=concurrency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency.d.ts","sourceRoot":"","sources":["../lib/concurrency.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAQlD;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEnE"}
@@ -0,0 +1,22 @@
1
+ import { availableParallelism } from 'node:os';
2
+ import pLimit from 'p-limit';
3
+ let limit = pLimit(availableParallelism());
4
+ /**
5
+ * Gets or sets the maximum number of concurrent native operations.
6
+ *
7
+ * The default value is the number of CPU cores (`os.availableParallelism()`).
8
+ * A value of `0` resets to the default.
9
+ */
10
+ export function concurrency(value) {
11
+ if (value !== undefined) {
12
+ if (!Number.isInteger(value) || value < 0) {
13
+ throw new TypeError('Concurrency must be a non-negative integer');
14
+ }
15
+ limit = pLimit(value === 0 ? availableParallelism() : value);
16
+ }
17
+ return limit.concurrency;
18
+ }
19
+ export function withConcurrency(fn) {
20
+ return limit(fn);
21
+ }
22
+ //# sourceMappingURL=concurrency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency.js","sourceRoot":"","sources":["../lib/concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,MAA8B,MAAM,SAAS,CAAC;AAErD,IAAI,KAAK,GAAkB,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;QACpE,CAAC;QACD,KAAK,GAAG,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,KAAK,CAAC,WAAW,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,eAAe,CAAI,EAAoB;IACrD,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC;AACnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7E;;GAEG;AACH,qBAAa,cAAc;IAOb,OAAO,CAAC,MAAM;IAN1B,6BAA6B;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAEpC,gBAAgB;gBACI,MAAM,EAAE,cAAc;IAK1C,oCAAoC;IAC9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjD,4EAA4E;IACrE,KAAK,IAAI,cAAc,CAAC,UAAU,CAAC;IAM1C,mDAAmD;IACnD,OAAO,IAAI,IAAI;IAIf,yCAAyC;IACzC,YAAY,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;CAGpC"}
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7E;;GAEG;AACH,qBAAa,cAAc;IAOb,OAAO,CAAC,MAAM;IAN1B,6BAA6B;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAEpC,gBAAgB;gBACI,MAAM,EAAE,cAAc;IAK1C,oCAAoC;IAC9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjD,4EAA4E;IACrE,KAAK,IAAI,cAAc,CAAC,UAAU,CAAC;IAM1C,mDAAmD;IACnD,OAAO,IAAI,IAAI;IAIf,yCAAyC;IACzC,YAAY,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;CAGpC"}
package/dist/document.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { withConcurrency } from './concurrency.js';
1
2
  import { PDFiumPage } from './page.js';
2
3
  /**
3
4
  * A loaded PDF document.
@@ -16,7 +17,7 @@ export class PDFiumDocument {
16
17
  }
17
18
  /** Gets a page by 0-based index. */
18
19
  async getPage(index) {
19
- return new PDFiumPage(await this.native.getPage(index));
20
+ return new PDFiumPage(await withConcurrency(() => this.native.getPage(index)));
20
21
  }
21
22
  /** Iterates over all pages. Caller is responsible for closing each page. */
22
23
  async *pages() {
@@ -30,7 +31,7 @@ export class PDFiumDocument {
30
31
  }
31
32
  /** Returns the bookmark/outline tree. */
32
33
  getBookmarks() {
33
- return this.native.getBookmarks();
34
+ return withConcurrency(() => this.native.getBookmarks());
34
35
  }
35
36
  }
36
37
  //# sourceMappingURL=document.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.js","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC;;GAEG;AACH,MAAM,OAAO,cAAc;IAOL;IANpB,6BAA6B;IACpB,SAAS,CAAS;IAC3B,sDAAsD;IAC7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AAC;IAED,oCAAoC;IACpC,KAAK,CAAC,OAAO,CAAC,KAAa;QACzB,OAAO,IAAI,UAAU,CAAC,MAAM,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjF,CAAC;IAED,4EAA4E;IAC5E,KAAK,CAAC,CAAC,KAAK;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,mDAAmD;IACnD,OAAO;QACL,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,yCAAyC;IACzC,YAAY;QACV,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ type PdfInput = Buffer | string;
4
4
  * Opens a PDF document from a Buffer or file path.
5
5
  */
6
6
  export declare function loadDocument(input: PdfInput, password?: string): Promise<PDFiumDocument>;
7
+ export { concurrency } from './concurrency.js';
7
8
  export { PDFiumDocument } from './document.js';
8
9
  export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
9
10
  export { PDFiumPage } from './page.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAchC;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cA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,kBAAkB,EAClB,IAAI,EACJ,cAAc,EACd,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,IAAI,EACJ,WAAW,EACX,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,GACf,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { dirname, resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { withConcurrency } from './concurrency.js';
4
5
  import { PDFiumDocument } from './document.js';
5
6
  import { parseNativeError } from './errors.js';
6
7
  const require = createRequire(import.meta.url);
@@ -21,12 +22,13 @@ const addon = require('../build/Release/pdfium.node');
21
22
  */
22
23
  export async function loadDocument(input, password) {
23
24
  try {
24
- return new PDFiumDocument(await addon.loadDocument(input, password));
25
+ return new PDFiumDocument(await withConcurrency(() => addon.loadDocument(input, password)));
25
26
  }
26
27
  catch (err) {
27
28
  throw parseNativeError(err);
28
29
  }
29
30
  }
31
+ export { concurrency } from './concurrency.js';
30
32
  export { PDFiumDocument } from './document.js';
31
33
  export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
32
34
  export { PDFiumPage } from './page.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/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@ export class PDFiumPage {
39
40
  }
40
41
  /** Extracts all text from the page. */
41
42
  getText() {
42
- return this.native.getText();
43
+ return withConcurrency(() => this.native.getText());
43
44
  }
44
45
  render(options) {
45
- return this.native.render(options);
46
+ return withConcurrency(() => this.native.render(options));
46
47
  }
47
48
  /** Returns the page object at the given index with type and bounds. */
48
- getObject(index) {
49
- return this.native.getObject(index);
49
+ async getObject(index) {
50
+ const obj = await withConcurrency(() => this.native.getObject(index));
51
+ // wrap the native render function on image objects with the concurrency semaphore
52
+ if (obj.type === 'image') {
53
+ const nativeRender = obj.render.bind(obj);
54
+ obj.render = ((opts) => withConcurrency(() => nativeRender(opts)));
55
+ }
56
+ return obj;
50
57
  }
51
58
  /** Iterates over all page objects (text spans, paths, images, etc.). */
52
59
  async *objects() {
@@ -60,19 +67,19 @@ export class PDFiumPage {
60
67
  }
61
68
  /** Returns all links on the page. */
62
69
  getLinks() {
63
- return this.native.getLinks();
70
+ return withConcurrency(() => this.native.getLinks());
64
71
  }
65
72
  /** Searches for text on the page. Returns matches with positions and bounding rects. */
66
73
  search(text, options) {
67
- return this.native.search(text, options);
74
+ return withConcurrency(() => this.native.search(text, options));
68
75
  }
69
76
  /** Returns all annotations on the page. */
70
77
  getAnnotations() {
71
- return this.native.getAnnotations();
78
+ return withConcurrency(() => this.native.getAnnotations());
72
79
  }
73
80
  /** Returns all form fields on the page. */
74
81
  getFormFields() {
75
- return this.native.getFormFields();
82
+ return withConcurrency(() => this.native.getFormFields());
76
83
  }
77
84
  }
78
85
  //# sourceMappingURL=page.js.map
package/dist/page.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"page.js","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,OAAO,UAAU;IAqBD;IApBpB,+CAA+C;IACtC,KAAK,CAAS;IACvB,gDAAgD;IACvC,MAAM,CAAS;IACxB,0BAA0B;IACjB,MAAM,CAAS;IACxB,gEAAgE;IACvD,WAAW,CAAS;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CAAC,CAAC,IAAyB,EAAE,EAAE,CAC/D,eAAe,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAA8B,CAAC;QAC5E,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,CAAC,OAAO;QACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,2CAA2C;IAC3C,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,qCAAqC;IACrC,QAAQ;QACN,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,wFAAwF;IACxF,MAAM,CAAC,IAAY,EAAE,OAAuB;QAC1C,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,2CAA2C;IAC3C,cAAc;QACZ,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,2CAA2C;IAC3C,aAAa;QACX,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import { availableParallelism } from 'node:os';
2
+ import pLimit, { type LimitFunction } from 'p-limit';
3
+
4
+ let limit: LimitFunction = pLimit(availableParallelism());
5
+
6
+ /**
7
+ * Gets or sets the maximum number of concurrent native operations.
8
+ *
9
+ * The default value is the number of CPU cores (`os.availableParallelism()`).
10
+ * A value of `0` resets to the default.
11
+ */
12
+ export function concurrency(value?: number): number {
13
+ if (value !== undefined) {
14
+ if (!Number.isInteger(value) || value < 0) {
15
+ throw new TypeError('Concurrency must be a non-negative integer');
16
+ }
17
+ limit = pLimit(value === 0 ? availableParallelism() : value);
18
+ }
19
+ return limit.concurrency;
20
+ }
21
+
22
+ export function withConcurrency<T>(fn: () => Promise<T>): Promise<T> {
23
+ return limit(fn);
24
+ }
package/lib/document.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { withConcurrency } from './concurrency.js';
1
2
  import { PDFiumPage } from './page.js';
2
3
  import type { Bookmark, DocumentMetadata, NativeDocument } from './types.js';
3
4
 
@@ -18,7 +19,7 @@ export class PDFiumDocument {
18
19
 
19
20
  /** Gets a page by 0-based index. */
20
21
  async getPage(index: number): Promise<PDFiumPage> {
21
- return new PDFiumPage(await this.native.getPage(index));
22
+ return new PDFiumPage(await withConcurrency(() => this.native.getPage(index)));
22
23
  }
23
24
 
24
25
  /** Iterates over all pages. Caller is responsible for closing each page. */
@@ -35,6 +36,6 @@ export class PDFiumDocument {
35
36
 
36
37
  /** Returns the bookmark/outline tree. */
37
38
  getBookmarks(): Promise<Bookmark[]> {
38
- return this.native.getBookmarks();
39
+ return withConcurrency(() => this.native.getBookmarks());
39
40
  }
40
41
  }
package/lib/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { dirname, resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { withConcurrency } from './concurrency.js';
4
5
  import { PDFiumDocument } from './document.js';
5
6
  import { parseNativeError } from './errors.js';
6
7
  import type { NativeAddon } from './types.js';
@@ -27,12 +28,13 @@ const addon: NativeAddon = require('../build/Release/pdfium.node');
27
28
  */
28
29
  export async function loadDocument(input: PdfInput, password?: string): Promise<PDFiumDocument> {
29
30
  try {
30
- return new PDFiumDocument(await addon.loadDocument(input, password));
31
+ return new PDFiumDocument(await withConcurrency(() => addon.loadDocument(input, password)));
31
32
  } catch (err) {
32
33
  throw parseNativeError(err);
33
34
  }
34
35
  }
35
36
 
37
+ export { concurrency } from './concurrency.js';
36
38
  export { PDFiumDocument } from './document.js';
37
39
  export {
38
40
  PDFiumError,
package/lib/page.ts CHANGED
@@ -1,6 +1,9 @@
1
+ import { withConcurrency } from './concurrency.js';
1
2
  import type {
2
3
  Annotation,
3
4
  FormField,
5
+ ImagePageObject,
6
+ ImageRenderOptions,
4
7
  Link,
5
8
  NativePage,
6
9
  PageObject,
@@ -48,7 +51,7 @@ export class PDFiumPage {
48
51
 
49
52
  /** Extracts all text from the page. */
50
53
  getText(): Promise<string> {
51
- return this.native.getText();
54
+ return withConcurrency(() => this.native.getText());
52
55
  }
53
56
 
54
57
  /** Renders the page to a file. */
@@ -56,12 +59,19 @@ export class PDFiumPage {
56
59
  /** Renders the page to an encoded image buffer (JPEG or PNG). */
57
60
  render(options?: PageRenderOptions): Promise<Buffer>;
58
61
  render(options?: PageRenderOptions): Promise<Buffer | void> {
59
- return this.native.render(options);
62
+ return withConcurrency(() => this.native.render(options));
60
63
  }
61
64
 
62
65
  /** Returns the page object at the given index with type and bounds. */
63
- getObject(index: number): Promise<PageObject> {
64
- return this.native.getObject(index);
66
+ async getObject(index: number): Promise<PageObject> {
67
+ const obj = await withConcurrency(() => this.native.getObject(index));
68
+ // wrap the native render function on image objects with the concurrency semaphore
69
+ if (obj.type === 'image') {
70
+ const nativeRender = (obj as ImagePageObject).render.bind(obj);
71
+ (obj as ImagePageObject).render = ((opts?: ImageRenderOptions) =>
72
+ withConcurrency(() => nativeRender(opts))) as ImagePageObject['render'];
73
+ }
74
+ return obj;
65
75
  }
66
76
 
67
77
  /** Iterates over all page objects (text spans, paths, images, etc.). */
@@ -78,21 +88,21 @@ export class PDFiumPage {
78
88
 
79
89
  /** Returns all links on the page. */
80
90
  getLinks(): Promise<Link[]> {
81
- return this.native.getLinks();
91
+ return withConcurrency(() => this.native.getLinks());
82
92
  }
83
93
 
84
94
  /** Searches for text on the page. Returns matches with positions and bounding rects. */
85
95
  search(text: string, options?: SearchOptions): Promise<SearchMatch[]> {
86
- return this.native.search(text, options);
96
+ return withConcurrency(() => this.native.search(text, options));
87
97
  }
88
98
 
89
99
  /** Returns all annotations on the page. */
90
100
  getAnnotations(): Promise<Annotation[]> {
91
- return this.native.getAnnotations();
101
+ return withConcurrency(() => this.native.getAnnotations());
92
102
  }
93
103
 
94
104
  /** Returns all form fields on the page. */
95
105
  getFormFields(): Promise<FormField[]> {
96
- return this.native.getFormFields();
106
+ return withConcurrency(() => this.native.getFormFields());
97
107
  }
98
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdfium-native",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Native Node.js bindings for PDFium",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -76,10 +76,16 @@
76
76
  "lint": "eslint --fix .",
77
77
  "lint:check": "eslint .",
78
78
  "format": "prettier --write .",
79
- "format:check": "prettier --check ."
79
+ "format:check": "prettier --check .",
80
+ "prepare": "husky"
81
+ },
82
+ "lint-staged": {
83
+ "*.{ts,js,json,md,yaml,yml}": "prettier --write",
84
+ "*.{ts,js}": "eslint --max-warnings 0"
80
85
  },
81
86
  "dependencies": {
82
- "node-addon-api": "^8.0.0"
87
+ "node-addon-api": "^8.0.0",
88
+ "p-limit": "^7.3.0"
83
89
  },
84
90
  "devDependencies": {
85
91
  "@eslint/js": "^10.0.1",
@@ -87,6 +93,8 @@
87
93
  "eslint": "^10.1.0",
88
94
  "eslint-config-prettier": "^10.1.8",
89
95
  "eslint-plugin-prettier": "^5.5.5",
96
+ "husky": "^9.1.7",
97
+ "lint-staged": "^16.4.0",
90
98
  "node-gyp": "^11.0.0",
91
99
  "prettier": "^3.8.1",
92
100
  "typescript": "^5.9.3",