afpp 1.1.1 → 1.2.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/dist/index.js CHANGED
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pdf2string = void 0;
4
4
  const promises_1 = require("node:fs/promises");
5
- const parsePdfFileBuffer = async (data, options) => import('pdfjs-dist/legacy/build/pdf.mjs').then(async (pdfjsLib) => {
5
+ const parsePdfFileBuffer = async (options) => import('pdfjs-dist/legacy/build/pdf.mjs').then(async (pdfjsLib) => {
6
6
  const loadingTask = pdfjsLib.getDocument({
7
- data,
8
- password: options?.password,
7
+ ...options,
8
+ verbosity: 0, // TODO enable for debug
9
9
  });
10
10
  const pdfDocument = await loadingTask.promise;
11
11
  const { numPages } = pdfDocument;
@@ -30,21 +30,39 @@ const parsePdfFileBuffer = async (data, options) => import('pdfjs-dist/legacy/bu
30
30
  await Promise.all(pagePromises);
31
31
  return pageContents;
32
32
  });
33
- const pdf2string = async (source, options) => {
34
- if (typeof source === 'string') {
35
- const fileBase64 = await (0, promises_1.readFile)(source, {});
36
- const data = new Uint8Array(fileBase64);
37
- return parsePdfFileBuffer(data, options);
33
+ /**
34
+ * Converts a PDF file from various input formats (Buffer, Uint8Array, string path, or URL) to a string.
35
+ *
36
+ * @async
37
+ * @function pdf2string
38
+ *
39
+ * @param {Buffer|Uint8Array|string|URL} input - The PDF source, which can be a file path, URL, Buffer, or Uint8Array.
40
+ * @param {Object} [options] - Optional parsing options for customizing the PDF parsing process.
41
+ * @param {string} [options.password] - The password for encrypted PDF files, if required.
42
+ *
43
+ * @since — v1.0.0
44
+ *
45
+ * @returns {Promise<string>} - A promise that resolves to the string representation of the PDF content.
46
+ *
47
+ * @throws {Error} Throws an error if the input type is invalid.
48
+ */
49
+ const pdf2string = async (input, options) => {
50
+ if (typeof input === 'string') {
51
+ const fileBuffer = await (0, promises_1.readFile)(input, {});
52
+ const data = new Uint8Array(fileBuffer);
53
+ return parsePdfFileBuffer({ data, ...options });
38
54
  }
39
- if (Buffer.isBuffer(source)) {
40
- const fileBase64 = await (0, promises_1.readFile)(source, {});
41
- const data = new Uint8Array(fileBase64);
42
- return parsePdfFileBuffer(data, options);
55
+ if (Buffer.isBuffer(input)) {
56
+ const data = new Uint8Array(input);
57
+ return parsePdfFileBuffer({ data, ...options });
43
58
  }
44
- if (source instanceof Uint8Array) {
45
- return parsePdfFileBuffer(source, options);
59
+ if (input instanceof Uint8Array) {
60
+ return parsePdfFileBuffer({ data: input, ...options });
46
61
  }
47
- throw new Error(`Invalid source type: ${typeof source}`);
62
+ if (input instanceof URL) {
63
+ return parsePdfFileBuffer({ url: input, ...options });
64
+ }
65
+ throw new Error(`Invalid source type: ${typeof input}`);
48
66
  };
49
67
  exports.pdf2string = pdf2string;
50
68
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAK5C,MAAM,kBAAkB,GAAG,KAAK,EAAE,IAAgB,EAAE,OAAsB,EAAE,EAAE,CAC5E,MAAM,CAAC,iCAAiC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;IAChE,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;QACvC,IAAI;QACJ,QAAQ,EAAE,OAAO,EAAE,QAAQ;KAC5B,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC;IAE9C,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC;IACjC,MAAM,YAAY,GAAa,IAAI,KAAK,CAAS,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpE,MAAM,YAAY,GAAmC,EAAE,CAAC;IAExD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,QAAQ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I,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,OAAO,kBAAkB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QACzB,OAAO,kBAAkB,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,KAAK,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEO,gCAAU"}
@@ -1,5 +1,21 @@
1
1
  type ParseOptions = {
2
2
  password?: string;
3
3
  };
4
- declare const pdf2string: (source: Buffer | Uint8Array | string, options?: ParseOptions) => Promise<string[]>;
4
+ /**
5
+ * Converts a PDF file from various input formats (Buffer, Uint8Array, string path, or URL) to a string.
6
+ *
7
+ * @async
8
+ * @function pdf2string
9
+ *
10
+ * @param {Buffer|Uint8Array|string|URL} input - The PDF source, which can be a file path, URL, Buffer, or Uint8Array.
11
+ * @param {Object} [options] - Optional parsing options for customizing the PDF parsing process.
12
+ * @param {string} [options.password] - The password for encrypted PDF files, if required.
13
+ *
14
+ * @since — v1.0.0
15
+ *
16
+ * @returns {Promise<string>} - A promise that resolves to the string representation of the PDF content.
17
+ *
18
+ * @throws {Error} Throws an error if the input type is invalid.
19
+ */
20
+ declare const pdf2string: (input: Buffer | URL | Uint8Array | string, options?: ParseOptions) => Promise<string[]>;
5
21
  export { pdf2string };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "afpp",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "another f*cking pdf parser",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -8,13 +8,14 @@
8
8
  "dist/**"
9
9
  ],
10
10
  "scripts": {
11
- "build": "tsc -p tsconfig.json",
11
+ "build": "tsc -p tsconfig.build.json",
12
12
  "commit": "git-cz",
13
13
  "lint": "eslint .",
14
14
  "prebuild": "rm -rf dist",
15
15
  "prepare": "husky",
16
- "test": "test",
17
- "typecheck": "tsc -p tsconfig.all.json --noEmit"
16
+ "test": "NODE_ENV=test npx tsx --test --test-reporter=@voxpelli/node-test-pretty-reporter test/*.test.ts",
17
+ "test:coverage": "NODE_ENV=test npx tsx --test --experimental-test-coverage test/*.test.ts",
18
+ "typecheck": "tsc -p tsconfig.json --noEmit"
18
19
  },
19
20
  "repository": {
20
21
  "type": "git",
@@ -38,7 +39,8 @@
38
39
  },
39
40
  "homepage": "https://github.com/l2ysho/afpp#readme",
40
41
  "dependencies": {
41
- "pdfjs-dist": "4.6.82"
42
+ "pdfjs-dist": "4.6.82",
43
+ "typescript": "5.6.2"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@commitlint/cli": "19.5.0",
@@ -46,6 +48,7 @@
46
48
  "@types/node": "22.5.5",
47
49
  "@typescript-eslint/eslint-plugin": "7.18.0",
48
50
  "@typescript-eslint/parser": "7.18.0",
51
+ "@voxpelli/node-test-pretty-reporter": "1.1.2",
49
52
  "commitizen": "4.3.0",
50
53
  "cz-conventional-changelog": "3.3.0",
51
54
  "eslint": "8.56.0",
@@ -61,7 +64,6 @@
61
64
  "husky": "9.1.6",
62
65
  "lint-staged": "15.2.10",
63
66
  "semantic-release": "24.1.1",
64
- "tsx": "4.19.1",
65
- "typescript": "5.6.2"
67
+ "tsx": "4.19.1"
66
68
  }
67
69
  }