afpp 0.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Richard Solar
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 ADDED
@@ -0,0 +1,2 @@
1
+ # afpp
2
+ Another f*cking pdf parser
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pdf2string = void 0;
4
+ const promises_1 = require("node:fs/promises");
5
+ const parsePdfFileBuffer = async (pathToFile) => {
6
+ const fileBase64 = await (0, promises_1.readFile)(pathToFile, {});
7
+ return import("pdfjs-dist/legacy/build/pdf.mjs").then(async (pdfjsLib) => {
8
+ const loadingTask = pdfjsLib.getDocument({
9
+ data: new Uint8Array(fileBase64),
10
+ });
11
+ const pdfDocument = await loadingTask.promise;
12
+ const { numPages } = pdfDocument;
13
+ const pageContents = new Array(numPages);
14
+ const pagePromises = [];
15
+ for (let pageNum = 1; pageNum <= numPages; pageNum += 1) {
16
+ pagePromises.push(pdfDocument.getPage(pageNum).then(async (page) => {
17
+ const textContent = await page.getTextContent({
18
+ includeMarkedContent: false,
19
+ });
20
+ // ? Type assertion of items to TextItem[] should be safe because {includeMarkedContent: false}
21
+ const items = textContent.items;
22
+ if (items.length === 0) {
23
+ console.log("empty page");
24
+ pageContents[pageNum - 1] = "";
25
+ }
26
+ else {
27
+ const pageText = items.map((item) => item.str || "").join(" ");
28
+ pageContents[pageNum - 1] = pageText;
29
+ }
30
+ }));
31
+ }
32
+ await Promise.all(pagePromises);
33
+ return pageContents;
34
+ });
35
+ };
36
+ //TODO check more valid types + password
37
+ const pdf2string = async (source) => {
38
+ if (typeof source === "string") {
39
+ return parsePdfFileBuffer(source);
40
+ // return console.error("implement");
41
+ }
42
+ if (Buffer.isBuffer(source)) {
43
+ return;
44
+ }
45
+ if (source instanceof Uint8Array) {
46
+ return;
47
+ }
48
+ throw new Error(`Invalid source type: ${typeof source}`);
49
+ };
50
+ exports.pdf2string = pdf2string;
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAa5C,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAkB,EAAE,EAAE;IACtD,MAAM,UAAU,GAAG,MAAM,IAAA,mBAAQ,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC,iCAAiC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QACvE,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;YACvC,IAAI,EAAE,IAAI,UAAU,CAAC,UAAU,CAAC;SACjC,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,MAA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,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAClC,qCAAqC;IACvC,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO;IACT,CAAC;IACD,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,MAAM,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEO,gCAAU"}
@@ -0,0 +1,2 @@
1
+ declare const pdf2string: (source: string | Buffer | Uint8Array) => Promise<string[] | undefined>;
2
+ export { pdf2string };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "afpp",
3
+ "version": "0.0.1",
4
+ "description": "another f*cking pdf parser",
5
+ "types": "./dist/types/index.d.ts",
6
+ "main": "./dist/index.js",
7
+ "files": [
8
+ "dist/**"
9
+ ],
10
+ "scripts": {
11
+ "test": "test",
12
+ "prebuild": "rm -rf dist",
13
+ "build": "tsc -p tsconfig.json"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+ssh://git@github.com/l2ysho/afpp.git"
18
+ },
19
+ "keywords": [
20
+ "pdf",
21
+ "parse-pdf",
22
+ "pdf-parser",
23
+ "pdf.js",
24
+ "pdf2text",
25
+ "pdf2json",
26
+ "pdfreader",
27
+ "pdf-to-text",
28
+ "parser-pdf"
29
+ ],
30
+ "author": "l2ysho",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/l2ysho/afpp/issues"
34
+ },
35
+ "homepage": "https://github.com/l2ysho/afpp#readme",
36
+ "dependencies": {
37
+ "pdfjs-dist": "4.6.82"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "22.5.5",
41
+ "semantic-release": "24.1.1",
42
+ "tsx": "4.19.1",
43
+ "typescript": "5.6.2"
44
+ }
45
+ }