Skip to content

Commit

Permalink
chore: initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Dec 13, 2024
0 parents commit e387f39
Show file tree
Hide file tree
Showing 34 changed files with 9,046 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
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
}
31 changes: 31 additions & 0 deletions README.md
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
36 changes: 36 additions & 0 deletions eslint.config.js
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"
}
}
];
18 changes: 18 additions & 0 deletions examples/main.ts
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 added examples/timetable.pdf
Binary file not shown.
50 changes: 50 additions & 0 deletions package.json
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"
}
}
Loading

0 comments on commit e387f39

Please sign in to comment.