Skip to content

Commit f027d31

Browse files
chore: use UnJS ESLint config
1 parent 1204c73 commit f027d31

File tree

18 files changed

+971
-725
lines changed

18 files changed

+971
-725
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": "@antfu"
2+
"extends": ["eslint-config-unjs"]
33
}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ permissions:
66
on:
77
push:
88
tags:
9-
- 'v*'
9+
- "v*"
1010

1111
jobs:
1212
release:

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"recommendations": ["dbaeumer.vscode-eslint"]
2+
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
33
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"editor.codeActionsOnSave": {
33
"source.fixAll.eslint": true
44
},
5-
"prettier.enable": false
5+
"editor.defaultFormatter": "esbenp.prettier-vscode",
6+
"editor.formatOnSave": true
67
}

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,32 @@ yarn add unpdf
3030
## Usage
3131

3232
```ts
33-
import { extractPDFText } from 'unpdf'
33+
import { extractPDFText } from "unpdf";
3434

3535
// Fetch a PDF file from the web
36-
const pdf = await fetch('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf')
37-
.then(res => res.arrayBuffer())
36+
const pdf = await fetch(
37+
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
38+
).then((res) => res.arrayBuffer());
3839

3940
// Or load it from the filesystem
40-
const pdf = await readFile('./dummy.pdf')
41+
const pdf = await readFile("./dummy.pdf");
4142

4243
// Pass the PDF buffer to the relevant method
43-
const { totalPages, text } = await extractPDFText(
44-
new Uint8Array(pdf), { mergePages: true }
45-
)
44+
const { totalPages, text } = await extractPDFText(new Uint8Array(pdf), {
45+
mergePages: true,
46+
});
4647
```
4748

4849
### Use Legacy Or Custom PDF.js Build
4950

5051
```ts
5152
// Before using any other methods, define the PDF.js module
52-
import { defineUnPDFConfig } from 'unpdf'
53+
import { defineUnPDFConfig } from "unpdf";
5354

5455
// Use the legacy build
5556
defineUnPDFConfig({
56-
pdfjs: () => import('pdfjs-dist/legacy/build/pdf.js')
57-
})
57+
pdfjs: () => import("pdfjs-dist/legacy/build/pdf.js"),
58+
});
5859

5960
// Now, you can use the other methods
6061
//
@@ -63,9 +64,9 @@ defineUnPDFConfig({
6364
### Access the PDF.js Module
6465

6566
```ts
66-
import { getResolvedPDFJS } from 'unpdf'
67+
import { getResolvedPDFJS } from "unpdf";
6768

68-
const { version } = await getResolvedPDFJS()
69+
const { version } = await getResolvedPDFJS();
6970
```
7071

7172
## Config
@@ -80,7 +81,7 @@ interface UnPDFConfiguration {
8081
* @example
8182
* () => import('pdfjs-dist/legacy/build/pdf.js')
8283
*/
83-
pdfjs?: () => Promise<typeof PDFJS>
84+
pdfjs?: () => Promise<typeof PDFJS>;
8485
}
8586
```
8687

@@ -91,47 +92,45 @@ interface UnPDFConfiguration {
9192
Define a custom PDF.js module, like the legacy build. Make sure to call this method before using any other methods.
9293

9394
```ts
94-
function defineUnPDFConfig(config: UnPDFConfiguration): Promise<void>
95+
function defineUnPDFConfig(config: UnPDFConfiguration): Promise<void>;
9596
```
9697

9798
### `getResolvedPDFJS`
9899

99100
Returns the resolved PDF.js module. If no build is defined, the latest version will be initialized.
100101

101102
```ts
102-
function getResolvedPDFJS(): Promise<typeof import('pdfjs-dist')>
103+
function getResolvedPDFJS(): Promise<typeof import("pdfjs-dist")>;
103104
```
104105

105106
### `getPDFMeta`
106107

107108
```ts
108-
function getPDFMeta(
109-
data: BinaryData | PDFDocumentProxy
110-
): Promise<{
111-
info: Record<string, any>
112-
metadata: Record<string, any>
113-
}>
109+
function getPDFMeta(data: BinaryData | PDFDocumentProxy): Promise<{
110+
info: Record<string, any>;
111+
metadata: Record<string, any>;
112+
}>;
114113
```
115114

116115
### `extractPDFText`
117116

118117
```ts
119118
function extractPDFText(
120119
data: BinaryData | PDFDocumentProxy,
121-
{ mergePages }?: { mergePages?: boolean }
120+
{ mergePages }?: { mergePages?: boolean },
122121
): Promise<{
123-
totalPages: number
124-
text: string | string[]
125-
}>
122+
totalPages: number;
123+
text: string | string[];
124+
}>;
126125
```
127126

128127
### `getImagesFromPage`
129128

130129
```ts
131130
function getImagesFromPage(
132131
data: BinaryData | PDFDocumentProxy,
133-
pageNumber: number
134-
): Promise<ArrayBuffer[]>
132+
pageNumber: number,
133+
): Promise<ArrayBuffer[]>;
135134
```
136135

137136
## License

build.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { defineBuildConfig } from 'unbuild'
1+
import { defineBuildConfig } from "unbuild";
22

33
export default defineBuildConfig({
4-
entries: ['src/index.web.ts', 'src/index.worker', 'src/index.node'],
4+
entries: ["src/index.web.ts", "src/index.worker", "src/index.node"],
55
clean: true,
66
declaration: true,
7-
externals: ['pdfjs-dist', 'pdfjs-serverless'],
7+
externals: ["pdfjs-dist", "pdfjs-serverless"],
88
rollup: {
99
emitCJS: true,
1010
},
11-
})
11+
});

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@
4949
"scripts": {
5050
"build": "unbuild",
5151
"dev": "unbuild --stub",
52-
"lint": "eslint .",
53-
"lint:fix": "eslint . --fix",
52+
"lint": "eslint \"**/*.ts\" --ignore-path .gitignore",
53+
"lint:fix": "npm run lint -- --fix",
54+
"format": "prettier \"**/*.{css,html,json,md,mjs,ts,vue,yml}\" --write",
55+
"format:check": "prettier \"**/*.{css,html,json,md,mjs,ts,vue,yml}\" --check",
5456
"release": "bumpp --commit --push --tag",
5557
"test": "tsx test/index.ts",
5658
"test:types": "tsc --noEmit"
@@ -60,12 +62,13 @@
6062
"pdfjs-serverless": "^0.2.1"
6163
},
6264
"devDependencies": {
63-
"@antfu/eslint-config": "^0.41.0",
6465
"@types/node": "^20.5.6",
6566
"bumpp": "^9.2.0",
6667
"eslint": "^8.48.0",
68+
"eslint-config-unjs": "^0.2.1",
6769
"pdfjs-dist": "^3.9.179",
6870
"pdfjs-serverless": "^0.2.1",
71+
"prettier": "^3.0.2",
6972
"tsx": "^3.12.7",
7073
"typescript": "^5.1.6",
7174
"unbuild": "^2.0.0"

0 commit comments

Comments
 (0)