-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e387f39
Showing
34 changed files
with
9,046 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Publish on NPM | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'js-v*.*.*' | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: latest | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
cache: 'pnpm' | ||
node-version: 20 | ||
registry-url: 'https://registry.npmjs.com' | ||
cache-dependency-path: 'pnpm-lock.yaml' | ||
|
||
- name: Publish package | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: | | ||
pnpm install && pnpm build | ||
npm publish --provenance --access public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"editor.detectIndentation": false, | ||
"editor.insertSpaces": true, | ||
"editor.tabSize": 2, | ||
|
||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
}, | ||
|
||
"eslint.useFlatConfig": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# `@literate.ink/pdf-inspector` | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @literate.ink/pdf-inspector | ||
yarn add @literate.ink/pdf-inspector | ||
pnpm add @literate.ink/pdf-inspector | ||
bun add @literate.ink/pdf-inspector | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript | ||
import { parsePDF } from "@literate.ink/pdf-inspector"; | ||
|
||
const pages = await parsePDF(buffer); | ||
|
||
for (const page of pages) { | ||
console.log(`Page of ${page.Width}x${page.Height}px`); | ||
console.log("- contains", page.Texts.length, "texts"); | ||
console.log("- contains", page.Fills.length, "fills"); | ||
} | ||
``` | ||
|
||
## Credits | ||
|
||
The JS/TS implementation is a fork of the following projects : | ||
|
||
- [`pdf2json`](https://github.com/modesty/pdf2json) is a [Node.js](http://nodejs.org/) module that parses and converts PDF from binary to JSON format | ||
- [`pdf.js`](https://github.com/mozilla/pdf.js/) but lighter because we only need a few things from it for what we are doing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = [ | ||
{ // Apply to `cjs`, `.mjs` and `.js` files. | ||
files: ["**/*.?([cm])js"] | ||
}, | ||
{ // Apply to `.ts` files. | ||
files: ["**/*.ts"], | ||
languageOptions: { | ||
parser: require("@typescript-eslint/parser"), | ||
parserOptions: { | ||
sourceType: "module" | ||
} | ||
} | ||
}, | ||
{ | ||
ignores: ["dist/**"], | ||
plugins: { | ||
stylistic: require("@stylistic/eslint-plugin") | ||
}, | ||
rules: { | ||
"stylistic/indent": ["error", 2], | ||
"stylistic/semi": ["error", "always"], | ||
"stylistic/eol-last": ["error", "always"], | ||
"stylistic/quotes": ["error", "double"], | ||
"stylistic/dot-location": ["error", "property"], | ||
"stylistic/array-bracket-spacing": ["error", "never"], | ||
"stylistic/arrow-parens": ["error", "always"], | ||
"stylistic/arrow-spacing": "error", | ||
"stylistic/block-spacing": ["error", "always"], | ||
"stylistic/brace-style": ["error", "stroustrup"], | ||
"stylistic/comma-dangle": ["error", "never"], | ||
"stylistic/comma-spacing": ["error", { before: false, after: true }], | ||
"stylistic/function-call-spacing": ["error", "never"], | ||
"stylistic/no-trailing-spaces": "error" | ||
} | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { parsePDF } from "../src"; | ||
// replace with this ^ "@literate.ink/pdf-inspector"; | ||
|
||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
|
||
void async function main () { | ||
const file = path.join(__dirname, "timetable.pdf"); | ||
const buffer = await fs.readFile(file); | ||
|
||
const pages = await parsePDF(buffer); | ||
|
||
for (const page of pages) { | ||
console.log(`Page of ${page.Width}x${page.Height}px`); | ||
console.log("- contains", page.Texts.length, "texts"); | ||
console.log("- contains", page.Fills.length, "fills"); | ||
} | ||
}(); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "@literate.ink/pdf-inspector", | ||
"version": "0.0.0", | ||
"description": "", | ||
"repository": "https://github.com/LiterateInk/PDFInspector", | ||
"sideEffects": false, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"import": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"checks": "tsc && eslint ." | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"pdf", | ||
"inspection", | ||
"scrapping" | ||
], | ||
"author": "LiterateInk <[email protected]> (https://literate.ink)", | ||
"homepage": "https://github.com/LiterateInk/PDFInspector", | ||
"bugs": { | ||
"url": "https://github.com/LiterateInk/PDFInspector/issues" | ||
}, | ||
"license": "GPL-3.0-or-later", | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"devDependencies": { | ||
"@stylistic/eslint-plugin": "^2.12.1", | ||
"@types/node": "^22.10.2", | ||
"@typescript-eslint/parser": "^8.18.0", | ||
"eslint": "^9.16.0", | ||
"terser": "^5.37.0", | ||
"tsup": "^8.3.5", | ||
"typescript": "^5.7.2" | ||
} | ||
} |
Oops, something went wrong.